【问题标题】:Does Scrapy support JavaScript for webcrawling?Scrapy 是否支持 JavaScript 进行网络爬虫?
【发布时间】:2013-07-14 19:31:57
【问题描述】:

听说scrapy 不支持javascript。我想知道我是否可以使用 scrapy 使用 crawlspider 来抓取指向我们 Intranet 站点的链接,我们的 Intranet 站点有 javascript,我相信它会在您单击链接时生成,但我不是 100% 确定。

但是视图源是由 xml-stylesheet 组成的,当我使用 firebug 时,它具有与 html 相同的数据。我也无法使用 html 标签来抓取网站,我需要使用 xml 标签才能抓取。我很困惑为什么它同时具有 html 和 xml 并且两者都有数据以及为什么我不能只抓取 xml 的 html?

我知道我可以使用 xml 标记抓取第一页,但我可以继续跟踪链接并继续抓取吗?

我是否仍然可以使用 scrapy 的 crawlspider 来抓取每个链接,或者我不能?如果我不能,你能推荐另一个我可以使用的工具吗?支持 javascripts 和 post authentication login (https).?

谢谢!

这是我使用 firebug 时的 HTML 数据(与 XML 相同的数据)

<tr>
<td class="crt">1</td>
<td class="listCell" align="center">
<td class="listCell" align="center">
<a href="/dis/packages.jsp?view=list&show=perdevice&device_gid=3651746C4173775343535452414567746D75643855673D3D53564A6151624D41716D534C68395A6337634E2F62413D3D&hwdid=probe0&subscrbid=6505550000&mdn=6505550000&maxlength=100">probe0</a>
</td>
<td class="listCell" align="center">
<a href="/dis/packages.jsp?view=list&show=perdevice&device_gid=3651746C4173775343535452414567746D75643855673D3D53564A6151624D41716D534C68395A6337634E2F62413D3D&hwdid=probe0&subscrbid=6505550000&mdn=6505550000&maxlength=100">6505550000</a>
</td>
<td class="listCell" align="center">
<a href="/dis/packages.jsp?view=timeline&show=perdevice&device_gid=3651746C4173775343535452414567746D75643855673D3D53564A6151624D41716D534C68395A6337634E2F62413D3D&hwdid=probe0&subscrbid=6505550000&mdn=6505550000&maxlength=100&date=20130716T141624949">2013-07-16 14:16:24.949</a>
</td>
<td class="cell" align="center">2013-07-16 14:16:24.949</td>
<td class="cell" align="left">1 - SMS_PullRequest_CS</td>
<td class="listCell" align="right">
<a href="/dis/profile_download?profileId=4294967295">4294967295</a>
</td>
<td class="listCell" align="center">
<a href="/dis/sessions.jsp?view=list&device_gid=3651746C4173775343535452414567746D75643855673D3D53564A6151624D41716D534C68395A6337634E2F62413D3D&hwdid=probe0&mdn=6505550000&subscrbid=6505550000&maxlength=100">view sessions</a>
</td>
<td class="listCell" align="center">
<a href="/dis/errors_agg.jsp?view=list&device_gid=3651746C4173775343535452414567746D75643855673D3D53564A6151624D41716D534C68395A6337634E2F62413D3D&hwdid=probe0&mdn=6505550000&subscrbid=6505550000&maxlength=100">view errors</a>
</td>
</tr>

这是我使用查看源 XML 样式表时的数据(与 HTML 相同的数据)

<row>
<cell type="href" href="/dis/packages.jsp?view=list&show=perdevice&device_gid=3651746C4173775343535452414567746D75643855673D3D53564A6151624D41716D534C68395A6337634E2F62413D3D&hwdid=probe0&mdn=6505550000&subscrbid=6505550000&maxlength=100">6505550000</cell>
<cell type="href" href="/dis/packages.jsp?view=list&show=perdevice&device_gid=3651746C4173775343535452414567746D75643855673D3D53564A6151624D41716D534C68395A6337634E2F62413D3D&hwdid=probe0&subscrbid=6505550000&mdn=6505550000&maxlength=100">probe0</cell>
<cell type="href" href="/dis/packages.jsp?view=list&show=perdevice&device_gid=3651746C4173775343535452414567746D75643855673D3D53564A6151624D41716D534C68395A6337634E2F62413D3D&hwdid=probe0&subscrbid=6505550000&mdn=6505550000&maxlength=100">6505550000</cell>
<cell type="href" href="/dis/packages.jsp?view=timeline&show=perdevice&device_gid=3651746C4173775343535452414567746D75643855673D3D53564A6151624D41716D534C68395A6337634E2F62413D3D&hwdid=probe0&subscrbid=6505550000&mdn=6505550000&maxlength=100&date=20130716T143636194">2013-07-16 14:36:36.194</cell>
<cell type="plain">2013-07-16 14:36:36.194</cell>
<cell type="plain">1 - SMS_PullRequest_CS</cell>
<cell type="href" href="/dis/profile_download?profileId=4294967295">4294967295</cell>
<cell type="href" href="/dis/sessions.jsp?view=list&device_gid=3651746C4173775343535452414567746D75643855673D3D53564A6151624D41716D534C68395A6337634E2F62413D3D&hwdid=probe0&mdn=6505550000&subscrbid=6505550000&maxlength=100">view sessions</cell>
<cell type="href" href="/dis/errors_agg.jsp?view=list&device_gid=3651746C4173775343535452414567746D75643855673D3D53564A6151624D41716D534C68395A6337634E2F62413D3D&hwdid=probe0&mdn=6505550000&subscrbid=6505550000&maxlength=100">view errors</cell>
</row>

【问题讨论】:

    标签: javascript python screen-scraping scrapy


    【解决方案1】:

    对于 JS,您通常会使用无头浏览器来执行您的 javascript。 Splash 和 scrapy-splash 中间件和Selenium 是那里的两个流行选择。

    【讨论】:

      【解决方案2】:

      我也在为 js 抓取而苦苦挣扎……高五。

      我知道scrapy是否响应来自特定网站的js的一种快速方法是从scrapy shell中检查。 http://doc.scrapy.org/en/latest/topics/shell.html你可以通过view(response)查看scrapy是如何理解你的请求url的。

      例如,view(response) 不显示来自 bestbuy 的产品评论,但它可以显示 eBay 产品评论。

      对于相关搜索,http://snipplr.com/all/tags/scrapy/ 可能会有所帮助。

      如果你在这里发布你的蜘蛛也可能会很有用。

      祝你好运!解决了就给我留言!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-03-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多