2017-07-26 85 views
0

nodejs對我來說是新的,我剛剛開始學習web刮板。問題是我需要廢棄一個受JS保護的網站。所以我需要從網站獲取手機,但只有在用戶點擊「顯示號碼」按鈕後纔會顯示帶有電話號碼的電話號碼。有沒有什麼方法或npm獲得數字?這裏是網站enter link description here,但它是俄語。所以按鈕是「показатьтелефоны」。先謝謝你!Nodejs寫一個可以讀取JS保護網站的刮板

+0

你將要使用的工具硒等做刮..它的工作原理與動態生成數據的網站,以及使用的數據輸入和虛擬鼠標交互的網站進行互動。 – zipzit

回答

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> 
+0

謝謝你的回答,我試過這樣做,但是它只輸出「錯誤請求」 –

+0

你有沒有試過這個方法?它爲你工作?也許我犯了錯誤 –