html - Python爬虫,翻页数据怎么爬,URL不变
大家讲道理
大家讲道理 2017-04-18 10:31:18
[Python讨论组]

网址:http://quote.eastmoney.com/ce...
我想爬所有页的名称数据,(这里只有两页),判断有没有下一页的条件该怎么写呢?
代码:

from selenium import webdriver
driver=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')

后面这里就不会写了。。。

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(4)
巴扎黑

可以判断每一页的条目,每一页共20条,如果当前页不足20条的时候,说明此页是最后一页了,爬完当前页就该停止了

PHP中文网

话说 这个表格不是都有个jsonp的返回接口吗?为什么还要爬?

PHPz

走的就是jsonp接口,直接拿就好了。

非要抓取的话,只能用selenium + phantomjs 之类的模拟页面去获取了。

伊谢尔伦

http://nufm.dfcfw.com/EM_Fina...{rank:[(x)],pages:(pc)}&token=7bc05d0d4c3c22ef9fca8c2a912d779c&jsName=quote_123&_g=0.5385195357178545

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号