Python爬蟲-批量爬取網頁URL的構建

Python爬蟲-批量爬取網頁URL的構建

  • 批量爬取網頁,需要根據網頁之間URL的規律,利用Python格式化輸出的format用法,來構造每頁的URL。下面以豆瓣小說的URL為例,來展示批量爬取網頁URL的構建:
  • 上代碼
<code>temp_url = 'https://book.douban.com/tag/⼩說?start={param}&type=T'
for page in range(1, 11):
url = temp_url.format(param=(page-1)*20)
print('第{}⻚url:'.format(page), url)/<code>
  • 上Jupyter Notebook返回結果
<code>第1⻚url: https://book.douban.com/tag/⼩說?start=0&type=T 

第2⻚url: https://book.douban.com/tag/⼩說?start=20&type=T

第3⻚url: https://book.douban.com/tag/⼩說?start=40&type=T

第4⻚url: https://book.douban.com/tag/⼩說?start=60&type=T

第5⻚url: https://book.douban.com/tag/⼩說?start=80&type=T

第6⻚url: https://book.douban.com/tag/⼩說?start=100&type=T

第7⻚url: https://book.douban.com/tag/⼩說?start=120&type=T

第8⻚url: https://book.douban.com/tag/⼩說?start=140&type=T

第9⻚url: https://book.douban.com/tag/⼩說?start=160&type=T

第10⻚url: https://book.douban.com/tag/⼩說?start=180&type=T/<code>


分享到:


相關文章: