scrapy框架爬虫翻页问题

qq_44388663 2019-04-19 05:15:39
哪位大神帮我看看,我有scrapy框架里的rules规则爬虫,为什么翻不了页,爬出来的数据是空的,爬的是腾讯招聘网

下面是代码

from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule


class Txzp1Spider(CrawlSpider):
name = 'txzp1'
# allowed_domains = ['hr.tencent.com']
start_urls = ['https://hr.tencent.com/position.php?lid=&tid=&keywords=java&start=0#a']

rules = (
Rule(LinkExtractor(allow=r'position.php?lid=&tid=&keywords=java&start=\d#a'),follow=True),
Rule(LinkExtractor(allow=r'position_detail.php?id=\d+&keywords=java&tid=0&lid=0'),
callback="parse_detail", follow=False),
)

def parse_detail(self, response):
print("===========")
title = response.xpath("//tr[@class='h']/td/text()").get()
region = response.xpath("//tr[@class='c bottomline']/td[1]/text()").get()
position_type = response.xpath("//tr[@class='c bottomline']/td[2]/text()").get()
number = response.xpath("//tr[@class='c bottomline']/td[3]/text()").get()
duty = response.xpath(
"//table[@class='tablelist textl']//tr[@class='c'][1]//ul[@class='squareli']/li/text()").getall()
yaoqiu = response.xpath(
"//table[@class='tablelist textl']//tr[@class='c'][2]//ul[@class='squareli']/li/text()").getall()
item = {"title": title, "position_type": position_type, "number": number, "region": region, "duty": duty,
"yaoqiu": yaoqiu}
print(item)
...全文
280 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
大白菜好吃 2020-03-09
  • 打赏
  • 举报
回复
规则写错了吧,写错才会是空
  • 打赏
  • 举报
回复
数据是空的:少了 yield item
一笑程序猴 2019-04-19
  • 打赏
  • 举报
回复
应该动态的把页码传过去给start的
一笑程序猴 2019-04-19
  • 打赏
  • 举报
回复
应该是这个地址的问题吧
LinkExtractor(allow=r'position.php?lid=&tid=&keywords=java&start=\d#a'),follow=True
start 后面是不是应该接一个具体的页码数字,这样相当于是传了个\d并没有翻页。所以也获取不到内容

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧