抓取不完整的 html

我是一名退休的程序员,但不熟悉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 部分<div id="app"></div>


有人可以阐明我做错了什么吗?我想抓取频道名称、订阅人数和观看次数


吃鸡游戏
浏览 240回答 1
1回答

肥皂起泡泡

可以理解。这是因为它们在页面加载期间通过另一个脚本呈现数据。在正常的scrapy 设置中,不会出现动态页面加载内容。要抓取该数据,您可以使用selenium.selenium-with-scrapy-for-dynamic-page对于另一种方式,您可以splash用于处理启用了 javascript 的内容。处理-javascript-in-scrapy-with-splash
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python