0
我是新来scrapy和stucked,当我尝试使用CrawlSpider从多个网站提取数据。需要CrawlSpider帮助scrapy
这里是我的代码:
class ivwSpider(CrawlSpider):
name = "ivw-online"
allowed_domains = ["ausweisung.ivw-online.de/"]
start_urls = ["http://ausweisung.ivw-online.de/index.php?i=1161&a=o44847"]
pagelink = LinkExtractor(allow=('index.php?i=1161&a=o\d{5}'))
print(pagelink)
rules = (Rule(pagelink, callback='parse_item', follow=True),)
def parse_item(self, response):
sel = Selector(response)
item = IVWItem()
item["Type"] = sel.xpath('//div[@class ="statistik"]//tr[1]//td/text()')[0].extract()
item["Zeitraum"] = sel.xpath('//div[@class ="tabelle"]//tr[1]//div[@style="width:210px; text-align:center;"]/text()')[0].extract()
item["Company"] = sel.xpath('//div[@class ="stammdaten"]//tr//td/text()').extract()[-1]
item["Video_PIs"] = sel.xpath('//div[@class ="tabelle"]//tr[11]//td[@class ="z5"]/text()').extract()
item["Video_Visits"] = sel.xpath('//div[@class ="tabelle"]//tr[11]//td[@class ="z4"]/text()').extract()
item["PIs"] = sel.xpath('//div[@class ="statistik"]//tr[3]//td/text()')[1].extract()
item["Visits"] = sel.xpath('//div[@class ="statistik"]//tr[1]//td/text()')[1].extract()
return item
当执行代码,返回任何结果。这是规则定义的问题吗?这里的任何帮助真的很感激!
我测试你的蜘蛛是正常的蜘蛛(不是CrawlSpider),它从start_url中提取数据。所以这个问题似乎是你已经猜到的CrawlSpider规则。对于我想要在页面上关注哪些链接,这并不是很明显。你可以编辑你的问题,并添加href应该遵循的细节? –
非常感谢您的支票。我喜欢的链接是ivw-ausweisung中不同竞争对手的在线数据网站。如:http://ausweisung.ivw-online.de/index.php?i=1161&a=o44847,http://ausweisung.ivw-online.de/index.php?i=1161&a=o44851等。唯一的区别这些网址之间的数字是i = 1161&a = o之后的数字...... –