python无法获取翻页表格的源代码

xiaohang0222 2017-06-14 10:56:09
想要下载http://www.sse.com.cn/disclosure/fund/etflist/该页的清单,但是获取不了第二页的下载链接

这是我写的代码
from selenium import webdriver
import time
from bs4 import BeautifulSoup
driver = webdriver.PhantomJS()
driver.get('http://www.sse.com.cn/disclosure/fund/etflist/')
time.sleep(3)
page = driver.page_source
soup = BeautifulSoup(page,"html.parser")
url1 = soup.find("div",{"id":"tabs-658545"}).findAll('a',{"target":"_blank"})
print(url1)
driver.close
...全文
193 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaohang0222 2017-06-18
  • 打赏
  • 举报
回复
引用 5 楼 uiuiy1 的回复:
做爬虫 用selenium是最简单粗暴的方法,打开浏览器开发者工具 找network 一个一个看 你会发现下面这个 http://query.sse.com.cn/infodisplay/queryETFNewAllInfo.do?jsonCallBack=jsonpCallback48879&isPagination=true&type=1&pageHelp.pageSize=25&pageHelp.pageCount=50&pageHelp.pageNo=2&pageHelp.beginPage=2&pageHelp.cacheSize=1&pageHelp.endPage=21&_=1497600000575

import requests
url = 'http://query.sse.com.cn/infodisplay/queryETFNewAllInfo.do?jsonCallBack=jsonpCallback37059&isPagination=true&type=1&pageHelp.pageSize=25&pageHelp.pageCount=50&pageHelp.pageNo=2&pageHelp.beginPage=2&pageHelp.cacheSize=1&pageHelp.endPage=21&_=1497600314848'
x = '''
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:zh-CN,zh;q=0.8,en;q=0.6
Cache-Control:no-cache
Connection:keep-alive
Cookie:yfx_c_g_u_id_10000042=_ck17061616000010471889457119969; yfx_f_l_v_t_10000042=f_t_1497600000033__r_t_1497600000033__v_t_1497600313002__r_c_0; VISITED_MENU=%5B%228363%22%5D
Host:query.sse.com.cn
Pragma:no-cache
Referer:http://www.sse.com.cn/disclosure/fund/etflist/
User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
'''
headers = dict([(d.split(':')[0], d.split(':', 1)[1]) for d in x.split('\n') if d])
print requests.get(url, headers=headers, timeout=30).content
谢谢回答,原谅我才入门,看不懂。。。。
xiaohang0222 2017-06-18
  • 打赏
  • 举报
回复
引用 6 楼 chuifengde 的回复:
[quote=引用 4 楼 xiaohang0222 的回复:] [quote=引用 3 楼 chuifengde 的回复:]
driver.set_window_size(1120,550)
x=driver.find_element_by_class_name("classStr")
x.click()
time.sleep(5)#这个时间可自定
。。。
运行之后提示"Unable to find element with class name 'classsStr'",我之前也是报这个错误。[/quote] 你写错了,三个小s加一个大S,实际是两个小s加一个大S[/quote] 非常感谢,终于可以了
chuifengde 2017-06-17
  • 打赏
  • 举报
回复
引用 4 楼 xiaohang0222 的回复:
[quote=引用 3 楼 chuifengde 的回复:]
driver.set_window_size(1120,550)
x=driver.find_element_by_class_name("classStr")
x.click()
time.sleep(5)#这个时间可自定
。。。
运行之后提示"Unable to find element with class name 'classsStr'",我之前也是报这个错误。[/quote] 你写错了,三个小s加一个大S,实际是两个小s加一个大S
chuifengde 2017-06-16
  • 打赏
  • 举报
回复
driver.set_window_size(1120,550)
x=driver.find_element_by_class_name("classStr")
x.click()
time.sleep(5)#这个时间可自定
。。。
屎克螂 2017-06-16
  • 打赏
  • 举报
回复
做爬虫 用selenium是最简单粗暴的方法,打开浏览器开发者工具 找network 一个一个看 你会发现下面这个 http://query.sse.com.cn/infodisplay/queryETFNewAllInfo.do?jsonCallBack=jsonpCallback48879&isPagination=true&type=1&pageHelp.pageSize=25&pageHelp.pageCount=50&pageHelp.pageNo=2&pageHelp.beginPage=2&pageHelp.cacheSize=1&pageHelp.endPage=21&_=1497600000575

import requests
url = 'http://query.sse.com.cn/infodisplay/queryETFNewAllInfo.do?jsonCallBack=jsonpCallback37059&isPagination=true&type=1&pageHelp.pageSize=25&pageHelp.pageCount=50&pageHelp.pageNo=2&pageHelp.beginPage=2&pageHelp.cacheSize=1&pageHelp.endPage=21&_=1497600314848'
x = '''
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:zh-CN,zh;q=0.8,en;q=0.6
Cache-Control:no-cache
Connection:keep-alive
Cookie:yfx_c_g_u_id_10000042=_ck17061616000010471889457119969; yfx_f_l_v_t_10000042=f_t_1497600000033__r_t_1497600000033__v_t_1497600313002__r_c_0; VISITED_MENU=%5B%228363%22%5D
Host:query.sse.com.cn
Pragma:no-cache
Referer:http://www.sse.com.cn/disclosure/fund/etflist/
User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
'''
headers = dict([(d.split(':')[0], d.split(':', 1)[1]) for d in x.split('\n') if d])
print requests.get(url, headers=headers, timeout=30).content
xiaohang0222 2017-06-16
  • 打赏
  • 举报
回复
引用 3 楼 chuifengde 的回复:
driver.set_window_size(1120,550)
x=driver.find_element_by_class_name("classStr")
x.click()
time.sleep(5)#这个时间可自定
。。。
运行之后提示"Unable to find element with class name 'classsStr'",我之前也是报这个错误。
xiaohang0222 2017-06-15
  • 打赏
  • 举报
回复
引用 1楼chuifengde 的回复:
运用driver的find_element方法定位到第二页的超链,再用click切换到第二页,再查找,你这个代码只是找第一页的内容
我在定位翻页链接和点击的时候总是报错,麻烦接着我的语句写一下可以吗?
chuifengde 2017-06-15
  • 打赏
  • 举报
回复
运用driver的find_element方法定位到第二页的超链,再用click切换到第二页,再查找,你这个代码只是找第一页的内容

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧