爬虫之CrawlSpider简单案例之读书网
2024-09-01 15:40:38
项目名py文件下
class DsSpider(CrawlSpider):
name = 'ds'
allowed_domains = ['dushu.com']
start_urls = ['https://www.dushu.com/book/1163_1.html'] rules = (
Rule(LinkExtractor(restrict_xpaths='//div[@class="pages"]'), callback='parse_item', follow=True),
) def parse_item(self, response):
item = {}
# print(response.url)
lis = response.xpath('//div[@class="bookslist"]/ul/li')
for li in lis:
item['name'] = li.xpath('.//h3/a/text()').extract_first()
item['link'] = li.xpath('.//h3/a/@href').extract_first()
item['author'] = li.xpath('.//p[1]/a/text()').extract_first()
#item['domain_id'] = response.xpath('//input[@id="sid"]/@value').get()
#item['name'] = response.xpath('//div[@id="name"]').get()
#item['description'] = response.xpath('//div[@id="description"]').get()
yield item
最新文章
- 关于django xadmin的学习改造(菜单名称,更改默认前缀数据库)
- perl文件句柄的传递
- 华清远见金牌讲师名家大讲堂Android开发篇成功举办
- XAMPP(Linux版-x86兼容)官网下载
- 关于javascript tween的学后小感想
- [C#基础]Func和Action学习
- iOS block 声明时和定义时的不同格式
- php安装libevent
- yarn安装部署
- Android 属性动画(Property Animation) 全然解析 (下)
- Z-Stack协议中几个重要概念的理解
- mysql 数据库优化要点
- mysql常用基础操作语法(十)~~子查询【命令行模式】
- POJ1743 Musical Theme(二分+后缀数组)
- 如何清除保存在IE浏览器上的账号密码
- Tomcat如何发布web项目
- Vue(六)过滤器
- java微信小程序调用支付接口(转)
- Rspec: everyday-rspec实操。5:controller test(了解基础)
- Java数组初始