无法运行Scrapy代码

时间:2017-05-05 03:55:34

标签: django python-2.7 scrapy

我写了以下代码:

spiders.test.py代码:

if

scraper.items的代码是:           来自scrapy.item import Item,Field

  from scrapy.spider import BaseSpider
  from scrapy.selector import HtmlXPathSelector
  from wscraper.items import WscraperItem


  class MySpider(BaseSpider):
  name = "ExampleSpider"
  allowed_domains = ["timeanddate.com"]
  start_urls = ["https://www.timeanddate.com/worldclock/"]

  def parse(self, response):
       hxs = HtmlXPathSelector(response)
       titles = hxs.select("/html/body/div[1]/div[8]/section[2]/div[1]/table/tbody").extract()
    #for titles in titles:
        #title = titles.select("a/text()").extract()
        #link = titles.select("a/@href").extract()
        print title

运行命令“scrapy crawl ExampleSpider”时出现以下错误:

      class WscraperItem(Item):
      # define the fields for your item here like:
      # name = scrapy.Field()
      title = Field()
      pass

2 个答案:

答案 0 :(得分:0)

蜘蛛名称必须为str,而不是list,因此:

class ExampleSpider(BaseSpider):
  name = "timeandzone"

否则Scrapy蜘蛛加载程序无法加载它。

答案 1 :(得分:0)

基本上,我有一个兼容性问题。所以,我安装了Scrapy1.3.3,这解决了问题,是的,如上面的答案中提到的蜘蛛名称应该是一个字符串。