I used basically this same code on lottery.net/powerball/numbers/#year no problem. Why is it not working this time? I have changed all the info I need to do as in the links and the XPath differences.
import scrapy
class MegaMillionsDrawingsSpider(scrapy.Spider):
name = 'mega_millions_drawings'
allowed_domains = ['www.lottery.net']
user_agent = # my user agent
def start_request(self):
start_urls = []
for i in reversed(range(1996,2023)):
current_url = 'http://www.lottery.net/mega-millions/numbers/'+ str(i)
start_urls.append(current_url)
for url in start_urls:
yield scrapy.Request(
url=url,
callback=self.parse,
headers={
'User-Agent': self.user_agent
}
)
def parse(self, response):
from scrapy.shell import inspect_response
inspect_response(response, self)
for drawing in response.xpath("//table[@class='prizes archive ']/tbody/tr"):
yield {
'date': drawing.xpath(".//td/a/text()[2]").get(),
#'url': response.urljoin(drawing.xpath(".//")).get(),
'first': drawing.xpath(".//td/ul[@class='multi results mega-millions']/li[@class='ball'][position() = 1]/text()").get(),
'second': drawing.xpath(".//td/ul[@class='multi results mega-millions']/li[@class='ball'][position() = 2]/text()").get(),
'third': drawing.xpath(".//td/ul[@class='multi results mega-millions']/li[@class='ball'][position() = 3]/text()").get(),
'fourth': drawing.xpath(".//td/ul[@class='multi results mega-millions']/li[@class='ball'][position() = 4]/text()").get(),
'fifth': drawing.xpath(".//td/ul[@class='multi results mega-millions']/li[@class='ball'][position() = 5]/text()").get(),
'mega-ball': drawing.xpath(".//td/ul[@class='multi results mega-millions']/li[@class='mega-ball']/text()").get()
}