【问题标题】:scrapy fetching incomplete html抓取不完整的html
【发布时间】:2019-06-17 16:34:24
【问题描述】:

我是一名退休的程序员,但刚接触 scrapy。实际上,这是我的第一个 python 项目,所以我可能做错了什么。

我在 anaconda 下启动了scrapy,并使用以下命令启动了一个 shell:

 scrapy shell "https://sailing-channels.com/by-subscribers"

看起来一切正常,我可以进行一些查询。

这是我的问题: 当我进入时:

response.css('body').extract()

我得到:['<body><noscript>If you\'re seeing this message, that means <strong>JavaScript has been disabled on your browser</strong>, please <strong>enable JS</strong> to make this app work.</noscript><div id="app"></div><script src="//apis.google.com/js/platform.js" async></script><script>!function(e,a,n,t,g,c,i){e.GoogleAnalyticsObject="ga",e.ga=e.ga||function(){(e.ga.q=e.ga.q||[]).push(arguments)},e.ga.l=1*new Date,c=a.createElement(n),i=a.getElementsByTagName(n)[0],c.async=1,c.src="//www.google-analytics.com/analytics.js",i.parentNode.insertBefore(c,i)}(window,document,"script"),ga("create","UA-15981085-17","auto"),ga("require","linkid"),ga("set","anonymizeIp",!0),ga("send","pageview")</script><script type="application/ld+json">{\n\t\t\t"@context": "http://schema.org",\n\t\t\t"@type": "Organization",\n\t\t\t"name": "Sailing Channels"\n\t\t\t"url": "https://www.sailing-channels.com",\n\t\t\t"logo": "https://sailing-channels.com/img/banner.png",\n\t\t\t"sameAs" : [\n\t\t\t\t"https://www.facebook.com/sailingchannels",\n\t\t\t\t"https://twitter.com/sailchannels"\n\t\t\t]\n\t }</script><script type="text/javascript" src="https://cdn.sailing-channels.com/1.15.9/main.1dad65fcb7a507930e1f.js"></script></body>']

我的问题是我期望更多。当我对 chrome 进行检查时,我在 <div id="app"></div> 中看到更多 /div 部分

有人能说明我做错了什么吗?我想抓取频道名称、订阅者数量和观看次数

谢谢

【问题讨论】:

    标签: python html scrapy


    【解决方案1】:

    可以理解。这是因为他们在页面加载期间通过另一个脚本呈现数据。

    在正常的scrapy设置中,不会出现动态页面加载内容。要抓取该数据,您可以使用selenium
    selenium-with-scrapy-for-dynamic-page

    对于另一种方法,您可以使用 splash 处理启用 javascript 的内容。
    handling-javascript-in-scrapy-with-splash

    【讨论】:

    • 谢谢。我会研究这些建议。
    猜你喜欢
    • 2017-07-24
    • 1970-01-01
    • 1970-01-01
    • 2018-07-13
    • 2016-05-18
    • 2021-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多