【Selenium爬取小说】

Selenium爬取小说

确定url

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

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

看class 或者 id 后面等于的值的时候 match 不一定是1 但是只要 这个标签下id=的这个值是唯一标识的即可 ,因为你搜索的是全部的整个页面下的这个值 但是classid=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()

爬取的结果

欢迎批评指正

相关推荐
深蓝电商API1 天前
爬虫日志系统如何设计?
爬虫
2601_962300471 天前
学习Python 爬虫路线
爬虫·python·学习路线·数据解析·反爬虫
Tinyfacture1 天前
postman抓取登录鉴权码token及设置全局变量
测试工具·postman
川石课堂软件测试1 天前
涨薪技术|Prometheus之HTTP API中使用PromQL
网络协议·测试工具·jmeter·http·单元测试·postman·prometheus
傻啦嘿哟2 天前
某招聘平台爬虫:爬取招聘岗位数据,分析各城市薪资水平
开发语言·爬虫·python
隐擎fox2 天前
深入理解网络传输层安全:TLS 指纹识别(JA3/JA4)原理与 Python 协议层检测实战
爬虫·python·网络协议·安全·网络安全·https
wuyk5552 天前
Python网络爬虫入门到实战 第01章:爬虫到底是什么?原理、流程、合法性、风险全解析(零基础必看)
开发语言·爬虫·python
x10n92 天前
Postman 汉化完整指南
测试工具·lua·postman
SEO_juper2 天前
你的服务器正在被 AI 爬虫“白嫖“带宽:2026 用日志把 Googlebot 和 AI 洪流分开算账(附脚本)
运维·人工智能·爬虫·python·chatgpt·seo