【问题标题】:Scraping review data from Tripadvisor with Python使用 Python 从 Tripadvisor 抓取评论数据
【发布时间】:2016-05-06 10:34:47
【问题描述】:

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

我没改,但出现“下载错误”。

/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 并解决了“下载错误”,但又出现了一个错误。

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

请再次帮助我。

【问题讨论】:

  • 你使用的是什么版本的 scrapy 和 Twisted?你能用scrapy version -v 的输出更新你的问题吗? (顺便说一句,that scrapy project on Github 似乎与 Scrapy 1.0+ 不兼容:我正在使用 scrapy 1.0.6 获得 TypeError: cannot concatenate 'str' and 'NoneType' objects
  • 谢谢。我将它从 0.24.4 更新到 0.24.5。 Scrapy:0.24.5 lxml:3.6.0.0 libxml2:2.9.2 Twisted:16.1.1 Python:2.7.11

标签: python scrapy tripadvisor


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2018-05-31
    • 1970-01-01
    • 1970-01-01
    • 2018-10-29
    • 2019-09-06
    • 1970-01-01
    • 2015-06-25
    • 2021-07-11
    • 1970-01-01
    相关资源
    最近更新 更多