【发布时间】:2017-07-14 11:54:55
【问题描述】:
我正在尝试抓取优惠券网站的优惠券,但是当我在 尝试运行爬虫显示错误。请帮助。 谢谢。
import scrapy
from scrapy.http import Request
from scrapy.selector import HtmlXPathSelector
from scrapy.spider import BaseSpider
class CuponationSpider(scrapy.spider):
name = "cupo"
allowed_domains = ["cuponation.in"]
start_urls = ["https://www.cuponation.in/firstcry-coupon#voucher"]
def parse(self, response):
all_items = []
divs_action = response.xpath('//div[@class="action"]')
for div_action in divs_action:
item = VoucherItem()
span0 = div_action.xpath('./span[@data-voucher-id]')[0]
item['voucher_id'] = span0.xpath('./@data-voucher-
id').extract()[0]
item['code'] = span0.xpath('./span[@class="code-
field"]/text()').extract()[0]
all_items.append(item)
>**Output** ERROR
File "/usr/lib/python2.7/urllib2.py", line 1198, in do_open
raise URLError(err)URLError: <urlopen error timed out>
2017-07-25 16:36:59 [boto] ERROR: Unable to read instance data, giving
up
【问题讨论】:
-
您的问题的答案在警告中。不要使用 scrapy.selector.HtmlXPathSelector 使用 scrapy.Selector
-
@Neil 问题仍未解决,我也试过了。
-
那么现在的警告是什么?错误是什么?
-
@Neil---File "/home/abhinav/Coupons/Voucher/Voucher/spiders/Couponation.py",第 13 行,解析中 hxs = scrapy.Selector(response) NameError: global name 'scrapy' 没有定义
-
上面的代码是你完整的scrapy文件吗?请检查你的缩进
标签: python xml xpath scrapy web-crawler