鍍金池/ 問答/數(shù)據(jù)分析&挖掘/ 如何處理這個(gè)顯示更多?

如何處理這個(gè)顯示更多?

import urllib.parse
import urllib.request
data={'q':'python'}
params = urllib.parse.urlencode(data)
req = urllib.request.Request("https://www.douban.com/search?{0}".format(params))
response = urllib.request.urlopen(req)
the_page = response.read().decode("utf-8")
with open("/tmp/python.html","w") as f:
     f.write(the_page)

可以獲得這個(gè)網(wǎng)頁的檢索結(jié)果,但是,點(diǎn)擊 獲得更多后,還有內(nèi)容。

如何模擬這個(gè)點(diǎn)擊更多,將其他的沒有顯示內(nèi)容也抓取出來?

回答
編輯回答
遺莣

分析api,請(qǐng)求接口

2018年8月11日 00:05
編輯回答
久礙你

這個(gè)搜索結(jié)果是動(dòng)態(tài)加載的
實(shí)際請(qǐng)求的接口形如下面這樣:

https://www.douban.com/j/search?q=python&start=0&subtype=item
https://www.douban.com/j/search?q=python&start=20&subtype=item
https://www.douban.com/j/search?q=python&start=40&subtype=item

可以看出每次加載20條數(shù)據(jù),點(diǎn)擊加載更多就會(huì)調(diào)用下一個(gè)請(qǐng)求。
那么可以寫個(gè)循環(huán)請(qǐng)求依次取得即可。

2018年9月4日 06:10