我已经创建了一个蜘蛛,它的目的是让我一个历史的看法乐透号码。脚本是工作,但它是返回第一个项目,然后复制它。
这是我的代码,它返回第一行,然后重复它的次数,有一行,但它应该返回每一行。
import scrapy
class LottoSpider(scrapy.Spider):
name = 'lottos'
start_urls = [
'https://www.lotteryextreme.com/powerball/results'
]
def parse(self, response):
for results in response.xpath('//*[contains(concat( " ", @class, " " ), concat( " ", "wyn", " " ))]'):
date = response.css('span.f20::text').get()
number1 = response.css('.results2 td::text')[0].extract()
number2 = response.css('.results2 td::text')[1].extract()
number3 = response.css('.results2 td::text')[2].extract()
number4 = response.css('.results2 td::text')[3].extract()
number5 = response.css('.results2 td::text')[4].extract()
powerball = response.css('.results2 td::text')[6].extract()
yield {
'date': date,
'number1': number1,
'number2': number2,
'number3': number3,
'number4': number4,
'number5': number5,
'powerball': powerball,
}
1条答案
按热度按时间xzabzqsa1#
在for循环中,需要使用
results
而不是response
。