使用Python从Tripadvisor中搜索审阅数据

时间:2016-05-06 10:34:47

标签: python scrapy tripadvisor

我是Python的初学者,想要从Tripadvisor中获取评论数据。 我试试这段代码https://github.com/magic890/tripadvisor-scraper

我没有改变它但是#34;错误下载"出现。

/home/natto/tripadvisor-scraper/tripadvisorbot/spiders/dmoz.py:7: ScrapyDeprecationWarning: tripadvisorbot.spiders.dmoz.DmozSpider inherits from deprecated class scrapy.spider.BaseSpider, please inherit from scrapy.spider.Spider. (warning only on first subclass, there may be others)
  class DmozSpider(BaseSpider):
2016-05-06 18:42:36+0900 [scrapy] INFO: Scrapy 0.24.4 started (bot: scrapybot)
2016-05-06 18:42:36+0900 [scrapy] INFO: Optional features available: ssl, http11
2016-05-06 18:42:36+0900 [scrapy] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'tripadvisorbot.spiders', 'FEED_FORMAT': 'json', 'SPIDER_MODULES': ['tripadvisorbot.spiders'], 'FEED_URI': 'output/result.json'}
2016-05-06 18:42:36+0900 [scrapy] INFO: Enabled extensions: FeedExporter, LogStats, TelnetConsole, CloseSpider, WebService, CoreStats, SpiderState
2016-05-06 18:42:36+0900 [scrapy] INFO: Enabled downloader middlewares: HttpAuthMiddleware, DownloadTimeoutMiddleware, UserAgentMiddleware, RetryMiddleware, DefaultHeadersMiddleware, MetaRefreshMiddleware, HttpCompressionMiddleware, RedirectMiddleware, CookiesMiddleware, HttpProxyMiddleware, ChunkedTransferMiddleware, DownloaderStats
2016-05-06 18:42:36+0900 [scrapy] INFO: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware
2016-05-06 18:42:36+0900 [scrapy] INFO: Enabled item pipelines: 
2016-05-06 18:42:36+0900 [tripadvisor-restaurant] INFO: Spider opened
2016-05-06 18:42:36+0900 [tripadvisor-restaurant] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2016-05-06 18:42:36+0900 [scrapy] DEBUG: Telnet console listening on 127.0.0.1:6023
2016-05-06 18:42:36+0900 [scrapy] DEBUG: Web service listening on 127.0.0.1:6080
2016-05-06 18:42:36+0900 [tripadvisor-restaurant] DEBUG: Redirecting (301) to <GET https://www.tripadvisor.com/RestaurantSearch?geo=60763&q=New+York+City%2C+New+York&cat=&pid=> from <GET http://www.tripadvisor.com/RestaurantSearch?geo=60763&q=New+York+City%2C+New+York&cat=&pid=>
2016-05-06 18:42:36+0900 [tripadvisor-restaurant] ERROR: Error downloading <GET https://www.tripadvisor.com/RestaurantSearch?geo=60763&q=New+York+City%2C+New+York&cat=&pid=>
    Traceback (most recent call last):

请告诉我你是否解决了这个问题。谢谢你的帮助。

我更新了Scrapy并解决了#34;错误下载&#34;,但出现了另一个错误。

2016-05-10 11:32:19+0900 [tripadvisor-restaurant] DEBUG: Redirecting (301) to <GET https://www.tripadvisor.com/RestaurantSearch?geo=60763&q=New+York+City%2C+New+York&cat=&pid=> from <GET http://www.tripadvisor.com/RestaurantSearch?geo=60763&q=New+York+City%2C+New+York&cat=&pid=>
2016-05-10 11:32:20+0900 [tripadvisor-restaurant] DEBUG: Crawled (200) <GET https://www.tripadvisor.com/RestaurantSearch?geo=60763&q=New+York+City%2C+New+York&cat=&pid=> (referer: None)
2016-05-10 11:32:20+0900 [tripadvisor-restaurant] ERROR: Spider error processing <GET https://www.tripadvisor.com/RestaurantSearch?geo=60763&q=New+York+City%2C+New+York&cat=&pid=>
    Traceback (most recent call last):
      File "/home/natto/anaconda2/lib/python2.7/site-packages/twisted/internet/base.py", line 825, in runUntilCurrent
        call.func(*call.args, **call.kw)
      File "/home/natto/anaconda2/lib/python2.7/site-packages/twisted/internet/task.py", line 671, in _tick
        taskObj._oneWorkUnit()
      File "/home/natto/anaconda2/lib/python2.7/site-packages/twisted/internet/task.py", line 517, in _oneWorkUnit
        result = next(self._iterator)
      File "/home/natto/anaconda2/lib/python2.7/site-packages/scrapy/utils/defer.py", line 57, in <genexpr>
        work = (callable(elem, *args, **named) for elem in iterable)
    --- <exception caught here> ---
      File "/home/natto/anaconda2/lib/python2.7/site-packages/scrapy/utils/defer.py", line 96, in iter_errback
        yield next(it)
      File "/home/natto/anaconda2/lib/python2.7/site-packages/scrapy/contrib/spidermiddleware/offsite.py", line 26, in process_spider_output
        for x in result:
      File "/home/natto/anaconda2/lib/python2.7/site-packages/scrapy/contrib/spidermiddleware/referer.py", line 22, in <genexpr>
        return (_set_referer(r) for r in result or ())
      File "/home/natto/anaconda2/lib/python2.7/site-packages/scrapy/contrib/spidermiddleware/urllength.py", line 33, in <genexpr>
        return (r for r in result or () if _filter(r))
      File "/home/natto/anaconda2/lib/python2.7/site-packages/scrapy/contrib/spidermiddleware/depth.py", line 50, in <genexpr>
        return (r for r in result or () if _filter(r))
      File "/home/natto/tripadvisor-scraper/tripadvisorbot/spiders/tripadvisor-restaurant.py", line 41, in parse
        tripadvisor_item['url'] = self.base_uri + clean_parsed_string(get_parsed_string(snode_restaurant, 'div[@class="quality easyClear"]/span/a[@class="property_title "]/@href'))
    exceptions.TypeError: cannot concatenate 'str' and 'NoneType' objects

请再次帮助我。

1 个答案:

答案 0 :(得分:0)

Twisted 15.0似乎改变了_getEndpoint method的签名。问题是fixed

Tripadvisor-scraper tested configuration与Scrapy 0.24.4。 尝试将scrapy更新为0.24.5。

pip install Scrapy==0.24.5 --force-reinstall