python selenium和xpath实现控制谷歌浏览器爬取小说
2019-07-03 22:31
239 查看
标题下载谷歌浏览器版本对应的控制驱动
查看自己的谷歌浏览器驱动,找到浏览器>>设置>>帮助>>关于chrome。
在浏览器驱动下载地址上下载对应的版本。
解压,然后将exe文件放在python的安装目录下的script目录下。(这里注意你当前pycharm的python解释器环境也在这个目录)
标题安装selenium三方库
命令行安装
pip install selenium
标题实现selenium和xpath结合控制浏览器下载小说
from time import sleep from selenium import webdriver #实例化一个浏览器驱动 chrome = webdriver.Chrome() def getText(url): url=chrome.get(url) content = chrome.find_elements_by_xpath("//div[@class='title_txtbox']") text = chrome.find_elements_by_xpath("//div[@class='content']/p") with open("read.txt",mode="a+") as f: for i in content: f.write(i.text+'\n') for i in text: f.writelines(i.text+'\n') sleep(1) next_chapter = chrome.find_elements_by_xpath("//a[@class='nextchapter']") if next_chapter: next_chapters = next_chapter[0].get_attribute('href') chrome.find_elements_by_xpath("//a[@class='nextchapter']")[0].click() getText(next_chapters) else: chrome.close() return 0 chrome.close() getText("http://book.zongheng.com/chapter/189169/3431546.html")
相关文章推荐
- 19、Selenium + Python 实现 UI 自动化测试-XPath and CSS cheat sheet
- Python笔记(二)--Python3.7通过selenium和geckodriver实现问卷星自动填写提交
- Selenium+WebDriver+Python 定时控制任务
- python3[爬虫实战] 使用selenium,xpath爬取京东手机(下)
- 配置docker实现python+selenium自动化
- python+selenium+autoit实现文件上传
- 下载小说(python实现)
- python selenium实现下拉 爬取淘宝商品信息
- python+ selenium 实现简历自动刷新
- python+selenium+phantomjs实现爬虫功能
- Python+Selenium实现新浪微博自动登录
- python的paramiko模块实现远程控制和传输示例
- 在Linux下实现Python+selenium+chrome的web自动化测试
- Mac OS下应用Python+Selenium实现web自动化测试
- Selenium3.x Python实现鼠标悬停的几种方法
- Python: UDP广播实现远程控制
- python selenium xpath定位方式
- python2.7+selenium2实现淘宝滑块自动认证
- python中实现控制小数点位数的方法
- Selenium Python 利用XPath定位元素