【发布时间】:2018-02-27 15:17:02
【问题描述】:
我正在尝试从 seatgeek 中获取票务信息,但我很难做到这一点。当我运行我的代码时,我得到了这个:
INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
我的想法是我会输入节目/活动的名称,scrapy 会抓取该节目的每个表演的 URL,然后抓取票价等。我的代码如下:
import scrapy
from seatgeek import items
class seatgeekSpider(scrapy.Spider):
name = "seatgeek_spider"
showname = input("Enter Show name (lower case please): ")
showname = showname.replace(' ', '-')
start_urls = "https://seatgeek.com/" + showname + "-tickets.html"
def parse_performance(self, response):
for href in response.xpath('//a[@class="event-listing-title"]/@href').extract():
yield scrapy.Request(
url= 'https://seatgeek.com/' + href,
callback=self.parse_ticketinv,
method="POST",
meta={'url': href})
def parse_ticketinv(self, response):
price = response.xpath('//span[@class="omnibox__listing__buy__price"]').extract()
performance = response.xpath('//div[@class="event-detail-words faint-words"]/text()').extract()
quantity = response.xpath('//div[@class="omnibox__seatview__availability"]/text()').extract()
seatinfo = response.xpath('//div[@class="omnibox__listing__section"]/text()').extract()
# creating scrapy items
item = items.seatgeekItem()
item['price'] = price
item['performance'] = performance
item['quantity'] = quantity
item['seatinfo'] = seatinfo
yield item
这是我的 items.py 代码:
import scrapy
class SeatgeekItem(scrapy.Item):
# define the fields for your item here like:
# name = scrapy.Field()
price = scrapy.Field()
performnace = scrapy.Field()
quantity = scrapy.Field()
seatinfo = scrapy.Field()
任何帮助将不胜感激 - 谢谢!
【问题讨论】:
标签: python web-scraping scrapy