- 积分
- 3644
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2014-10-21
- 最后登录
- 1970-1-1
![未绑定新浪微博用户 新浪微博达人勋](source/plugin/sina_login/img/gray.png)
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
from selenium import webdriver
import time,os
t_start=time.time()#记录起始时间
url='https://www.zhcw.com/kjxx/ssq/?type=0'#双色球官网
browser=webdriver.PhantomJS()
browser.get(url)
browser.implicitly_wait(10)
#等待响应,似乎这里设置好后,后面的响应等待都按会这个时间来
print('网页标题:\n',browser.title)
#选择近100期的:
XPathPos="//span[@class='annq'][@data-z='100']"
x=browser.find_element_by_xpath(XPathPos)
x.click()
#确定双色球号码位置:
XPathPos="//td[@class='kjhm']"
x=browser.find_elements_by_xpath(XPathPos)
print('元素数=',len(x))
for i in x:
print(i.text)#输出号码,这里有个乱入的,可后期处理
#找到“转到最后一页>>”元素:
XPathPos="//a[@title='last']"
x=browser.find_elements_by_xpath(XPathPos)
print('翻页元素数=',len(x))
x=x[0]
x.click()#翻页
#想要页面加载完,implicitly_wait不好使,得直接睡眠等待
time.sleep(5)
#保存并打开网页:
htmlfile=r'C:\Users\Administrator\Desktop\最后一页.html'
fp=open(htmlfile,'w',encoding=('utf-8'))
fp.write(browser.page_source)
fp.close()
os.startfile(htmlfile)
t_end=time.time()#记录结束时间
print('耗时=%0.1f'%(t_end-t_start))
结果:保存的html文本见附件,打印结果如下:
网页标题:
双色球开奖结果_中彩网
元素数= 60
070914263031
04
020307081722
15
060916182229
11
......
060917222426
16
020609142225
04
翻页元素数= 1
耗时=56.1
|
|