使用scrapy时出错

时间:2016-08-27 11:31:31

标签: ubuntu-14.04 scrapy-spider

我正在尝试使用scrapy提取数据,我跟着the video但是我收到了错误

test.py

from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from craigslist_sample.items import CraigslistSampleItem
from scrapy.http import Request

class MySpider(BaseSpider):
    name = "craig"
    allowed_domain = ["craigslist.org"]
    start_urls = ["http://sfbay.craigslist.org/search/sfc/npo"]

    def parse(self,response):
        hxs = HtmlXPathSelector(response)
        titles = hxs.select("//p")
        items = []
        for titles in titles:
            item = CraigslistSampleItem()
            item["title"] = titles.select("a/text()").extract()
            item["link"] = titles.select("a/@href").extract()
            item.append(item)
        return items

items.py

from scrapy.item import Item, Field

class CraigslistSampleItem(Item):
    title = Field()
    link = Field()#import scrapy

这是两个文件

运行test.py后出现以下错误

test.py:1: ScrapyDeprecationWarning: Module `scrapy.spider` is deprecated, use `scrapy.spiders` instead
  from scrapy.spider import BaseSpider
Traceback (most recent call last):
  File "test.py", line 5, in <module>
    from craigslist_sample.items import CraigslistSampleItem
ImportError: No module named craigslist_sample.items

所以我必须尽快做出改变......

我的scrapy的版本是1.1.2&amp; python版本是2.7.6

谢谢.... :)

0 个答案:

没有答案