【问题标题】:Nodejs writing a scraper that can read JS protected websitesNodejs 写一个可以读取 JS 保护网站的爬虫
【发布时间】:2017-07-26 20:38:33
【问题描述】:

nodejs 对我来说是新的,我刚刚开始学习网络爬虫。问题是我需要废弃一个受 JS 保护的网站。所以我需要从网站上获取电话,但是只有在用户点击“显示号码”按钮后才会出现带有电话号码的 div。有什么方法或 npm 来获取数字吗?这是网站enter link description here,但它是俄语的。所以按钮是“показать телефоны”。提前谢谢!

【问题讨论】:

  • 您将需要使用像 selenium 这样的工具来进行抓取。它适用于具有动态生成数据的站点,并使用数据输入和虚拟鼠标交互与站点进行交互。跨度>

标签: node.js npm web-scraping scraper


【解决方案1】:

转到包含电话号码的页面并打开控制台并查看您的网络工具。当你点击一个电话号码时,它会发出一个 ajax 请求并给你一个很好的格式化响应

{"status":"ok","phone":"+7 (727) 317-20-86","html_tooltip":"<section class=\"company-phones-tooltip\">\r\n    <div class=\"company-phones-tooltip__wrap\">\r\n        <header class=\"company-phones-tooltip__header\">\r\n            Inform the manager that you learned the information on Allbiz.\r\n        <\/header>\r\n        <ul class=\"company-phones-tooltip-list\">\r\n                            <li class=\"company-phones-tooltip-list__item\">\r\n                    <div class=\"company-phones-tooltip-list__name\">\r\n                        management\r\n                    <\/div>\r\n                    <div class=\"company-phones-tooltip-list__number\">\r\n                        +7 (727) 317-20-86\r\n                    <\/div>\r\n                <\/li>\r\n                    <\/ul>\r\n        <footer class=\"company-phones-tooltip__footer\">\r\n            <a class=\"company-phones-tooltip__link\" href=\"https:\/\/12246-kz.all.biz\/contacts\" target=\"_blank\">\r\n                Show all contacts\r\n            <\/a>\r\n        <\/footer>\r\n    <\/div>\r\n<\/section>"}

为了模拟这一点,您只需在抓取页面后使用正确的参数调用http://api.all.biz/ajax/viewphonenew/kz 端点。此端点所需的所有查询参数都在 html 元素中。

<div class="company-phones__wrap" data-click="company-phones" data-entid="58474" data-verify="bYjmFpAfm5QWOgIjx8cyNOARdSG3FIoPo6he2dYGLIc=" data-phone="Zk6xDyCXPMqWMXgTaCI51A24FHIsDwuy8IaF993LsHI=" data-country="kz" data-placement="company-phones-tooltip___3" data-tooltip-direction="left" data-source="list">
        <div class="company-phones__code">+7(7&nbsp;</div>
        <div class="company-phones__main" data-ga="show-phones-list" data-ga-id="">
            <div class="company-phones__btn">Показать телефоны</div>
        </div>
    </div>

【讨论】:

  • 谢谢你的回答,我试过这样做,但它只输出“错误请求”
  • 你试过这个方法吗?它对你有用吗?也许我做错了什么
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多