【Selenium爬取小说】

Selenium爬取小说

确定url

找到你所需要的网站 然后进行分析检查 。

==注意: 进行搜索元素时 会有一个ctrl+f的操作

看class 或者 id 后面等于的值的时候 match 不一定是1 但是只要 这个标签下id=的这个值是唯一标识的即可 ,因为你搜索的是全部的整个页面下的这个值 但是class[id=xxx]这个会可能是唯一的。

进行分析页面在爬取

可以发现都在dd标签下

多层爬取 进入这个页面 然后爬取这一章的内容

可以发现内容都在这个标签下

我们打开一个文件接受这个文本即可

爬虫代码

python 复制代码
import time
from selenium import webdriver
from selenium.webdriver.common.by import By

file = open('./output/xxx/明克街13号.txt','a',encoding= 'utf-8')
driver = webdriver.Firefox()
url = 'https://www.xxxxx.bz/book/54529/'
driver.get(url)
dd_list =driver.find_elements(By.XPATH,"//div[@id='list']/dl/dd")
print(dd_list)
number = 1
for i in range(12,len(dd_list)):
    print(f'爬取第{number}章')
    detail_url = dd_list[i].find_element(By.XPATH,'a').get_attribute('href')
    print(detail_url)
    driver_chmo = webdriver.Chrome()
    driver_chmo.get(detail_url)
    response = driver_chmo.find_element(By.XPATH,'//div[@id="content"]')
    print(response.text)
    file.write(response.text+f'\n   第{number}章   \n')
    number = number + 1
    time.sleep(3)
file.close()

爬取的结果

欢迎批评指正

相关推荐
秃了也弱了。8 小时前
WireShark:非常好用的网络抓包工具
网络·测试工具·wireshark
敲上瘾10 小时前
Linux系统cgroups资源精细化控制基础
linux·测试工具·docker·压力测试·cgroups
TLuoQiu11 小时前
小电视视频内容获取GUI工具
爬虫·python
gc_229915 小时前
使用HtmlAgilityPack+PuppeteerSharp+iText7抓取Selenium帮助文档
selenium·itext7·htmlagilitypack·puppeteersharp
天才测试猿16 小时前
常见的Jmeter压测问题
自动化测试·软件测试·python·测试工具·jmeter·职场和发展·压力测试
麦麦大数据20 小时前
F004 新闻可视化系统爬虫更新数据+ flask + mysql架构
爬虫·mysql·flask·可视化·新闻
python-行者21 小时前
akamai鼠标轨迹
爬虫·python·计算机外设·akamai
NEUMaple2 天前
python爬虫(四)----requests
开发语言·爬虫·python
电商API_180079052472 天前
大规模调用淘宝商品详情 API 的分布式请求调度实践
服务器·数据库·分布式·爬虫
小白学大数据2 天前
1688商品数据抓取:Python爬虫+动态页面解析
爬虫·python·okhttp