html - Python爬蟲,翻頁數據怎么爬,URL不變
問題描述
網址:http://quote.eastmoney.com/ce...我想爬所有頁的名稱數據,(這里只有兩頁),判斷有沒有下一頁的條件該怎么寫呢?代碼:
from selenium import webdriverdriver=webdriver.PhantomJS()url=’http://quote.eastmoney.com/center/list.html#28003684_0_2’driver.get(url)usoup = BeautifulSoup(driver.page_source, ’xml’)n=[]while True: t=usoup.find(’table’,{’id’:’fixed’}) utable=t.find_all(’a’,{’target’:’_blank’}) for i in range(len(utable)): if i % 6 ==1: n.append(utable[i].text) if #停止條件怎么寫: break driver.find_element_by_xpath(r’//*@id='pagenav']/a[2]’).click() usoup = BeautifulSoup(driver.page_source, ’xml’)
后面這里就不會寫了。。。
問題解答
回答1:可以判斷每一頁的條目,每一頁共20條,如果當前頁不足20條的時候,說明此頁是最后一頁了,爬完當前頁就該停止了
回答2:話說 這個表格不是都有個jsonp的返回接口嗎?為什么還要爬?
回答3:走的就是jsonp接口,直接拿就好了。
非要抓取的話,只能用selenium + phantomjs 之類的模擬頁面去獲取了。
回答4:http://nufm.dfcfw.com/EM_Fina...{rank:[(x)],pages:(pc)}&token=7bc05d0d4c3c22ef9fca8c2a912d779c&jsName=quote_123&_g=0.5385195357178545
