nodejs对我来说是新的,我刚开始学习网络刮刀。问题是我需要废弃一个受JS保护的网站。所以我需要从网站上获取电话,但只有在用户点击“显示号码”按钮后才显示带有电话号码的div。有没有什么办法可以获得这些数字?这是网站enter link description here,但它是俄语。所以按钮是“показатьтелефоны”。提前谢谢!
答案 0 :(得分: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 </div>
<div class="company-phones__main" data-ga="show-phones-list" data-ga-id="">
<div class="company-phones__btn">Показать телефоны</div>
</div>
</div>