【问题标题】:Scrapy-Splash not rendering this pageScrapy-Splash 不呈现此页面
【发布时间】:2018-12-28 16:37:28
【问题描述】:

谁能帮助理解为什么 Splash 不会呈现此页面,以便我可以抓取它。

网址:https://www6.hertsmere.gov.uk/online-applications/weeklyListResults.do?action=firstPage

这是我写的蜘蛛:

class planningApplications(scrapy.Spider):
  name = 'planning-application'

def start_requests(self):
    yield SplashRequest(
        url='https://www6.hertsmere.gov.uk/online- 
applications/weeklyListResults.do?action=firstPage',
        callback=self.parse
    )

def parse(self, response):
    self.log('I just visited: ' + response.url)
    self.log(response.body_as_unicode())
    item = {
        'test': response.xpath('//*[@id="searchresults"]/li[1]/a').extract_first()
    }
    yield item

这是我在 settings.py 中的 Splash 相关设置:

SPLASH_URL = 'http://localhost:8050/'

 DOWNLOADER_MIDDLEWARES = {
   'scrapy_splash.SplashCookiesMiddleware': 723,
   'scrapy_splash.SplashMiddleware': 725,
   'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware': 
810, 
}

SPIDER_MIDDLEWARES = {
    'scrapy_splash.SplashDeduplicateArgsMiddleware': 100,
}

DUPEFILTER_CLASS = 'scrapy_splash.SplashAwareDupeFilter'
HTTPCACHE_STORAGE = 'scrapy_splash.SplashAwareFSCacheStorage'

我尝试使用以下代码行使用 scrapy shell 并打印出响应 unicode,但保存计划应用程序的 html 不存在。

 scrapy shell 'http://localhost:8050/render.html?url=https://www6.hertsmere.gov.uk/online-applications/pagedSearchResults.do?action=page&searchCriteria.page=2'

如果使用 scrapy-splash 的方法在网站上不起作用,你会推荐使用 selenium 和 scrapy 吗?

任何帮助将不胜感激:)

【问题讨论】:

    标签: python html web-scraping scrapy scrapy-splash


    【解决方案1】:

    我用你的配置做了新的蜘蛛,问题出在robots.txt

    调试:robots.txt 禁止:https://www6.hertsmere.gov.uk/online-applications/weeklyListResults.do?action=firstPage>

    爬取之前需要先下载robots.txt。要更改它,您需要将 False 赋值给 ROBOTSTXT_OBEY

    去找你settings.py 改一下。

    ROBOTSTXT_OBEY = False
    

    我收到的一些输出

    http://www.w3.org/1999/xhtml" xml:lang="en" cla$s="js"><head>
    
    <!-- #BeginEditable "doctitle" -->
    <title>
        Error
    </title>
    

    【讨论】:

    • 感谢您的回复,但这无助于获取数据
    • 你运行docker吗?
    • 当你使用scrapy shell 时,你能证明你回到了终端吗?你也可以去localhost:8050你看到了什么
    • 我在 aws 上的 linux 虚拟机上运行它,但是当我运行 scrapy shell 'localhost:8050/render.html?url=https://www6.hertsmere.gov.uk/…' 时,我得到的只是一些 html 而不是包含计划应用程序详细信息的 div
    • 你不能从那里得到错误吗?我需要查看错误,因为在我的情况下它有效,可能还有其他问题
    猜你喜欢
    • 2019-01-24
    • 1970-01-01
    • 2018-02-13
    • 1970-01-01
    • 1970-01-01
    • 2021-08-16
    • 2020-01-04
    • 2017-12-22
    • 2018-05-30
    相关资源
    最近更新 更多