我正在尝试刮一个投注网站。但是,当我在scrapy shell中检查检索到的数据时,什么也没收到。
我需要的xpath是:// * [@@ =“ =” yui_3_5_0_1_1562259076537_31330“],当我在shell中编写时,这就是我得到的:
In [18]: response.xpath ( '//*[@id="yui_3_5_0_1_1562259076537_31330"]')
Out[18]: []
输出为[],但我希望可以从中提取href。
当我使用Chrome的“检查”工具时,尽管该网站仍在加载,但此ID的轮廓为紫色。这是否意味着该站点正在使用JavaScipt?如果这是真的,这是为什么scrapy找不到项目并返回[]的原因吗?
答案 0 :(得分:0)
这是items.py文件
import scrapy
class LifeMatchsItem(scrapy.Item):
Event = scrapy.Field() # Name of event
Match = scrapy.Field() # Teams1 vs Team2
Date = scrapy.Field() # Date of Match
这是我的蜘蛛代码
import scrapy
from LifeMatchesProject.items import LifeMatchsItem
class LifeMatchesSpider(scrapy.Spider):
name = 'life_matches'
start_urls = ['http://www.betfair.com/sport/home#sscpl=ro/']
custom_settings = {'FEED_EXPORT_ENCODING': 'utf-8'}
def parse(self, response):
for event in response.xpath('//div[contains(@class,"events-title")]'):
for element in event.xpath('./following-sibling::ul[1]/li'):
item = LifeMatchsItem()
item['Event'] = event.xpath('./a/@title').get()
item['Match'] = element.xpath('.//div[contains(@class,"event-name-info")]/a/@data-event').get()
item['Date'] = element.xpath('normalize-space(.//div[contains(@class,"event-name-info")]/a//span[@class="date"]/text())').get()
yield item
这就是结果