【发布时间】:2021-01-25 12:22:33
【问题描述】:
我正在尝试用解析后的数据填充我的项目,但出现错误:
item = items()
NameError: name 'items' is not defined**
当我运行scrapy crawl usa_florida_scrapper
这是我的蜘蛛代码:
import scrapy
import re
class UsaFloridaScrapperSpider(scrapy.Spider):
name = 'usa_florida_scrapper'
start_urls = ['https://www.txlottery.org/export/sites/lottery/Games/index.html']
def parse(self, response):
item = items()
print('++++++ Latest Results for Powerball ++++++++++')
power_ball_html = (response.xpath("/html/body/div[1]/div[3]/div/div[1]/div[3]/div[2]/ol").extract_first())
power_balls=(",".join(re.findall(r'<span>(.+)</span>',power_ball_html)))
power_ball_special=(response.xpath("/html/body/div[1]/div[3]/div/div[1]/div[3]/div[2]/ol/li[6]/span[contains(@class, 'powerball')]/text()").get())
power_ball_jackpot = response.xpath('/html/body/div[1]/div[3]/div/div[1]/div[3]/div[1]/h1/text()').get()
power_ball_multiplier = response.xpath('/html/body/div[1]/div[3]/div/div[1]/div[3]/div[2]/div[2]/h3/span/text()').get()
item['LotteryKey']= '227'
item['Date']= '2020-10-10'
item['Balls']= power_balls
item['SpecialBalls']= power_ball_special
item['Multiplier']= power_ball_multiplier
item['JackpotValue']= power_ball_jackpot
yield item
这是我的商品代码 items.py:
import scrapy
class KariedanielItem(scrapy.Item):
# define the fields for your item here like:
LotteryKey = scrapy.Field()
Date = scrapy.Field()
Balls = scrapy.Field()
SpecialBalls = scrapy.Field()
Multiplier = scrapy.Field()
JackpotValue = scrapy.Field()
pass
【问题讨论】:
标签: python web-scraping scrapy