【问题标题】:web scraping with node npm request使用节点 npm 请求进行网络抓取
【发布时间】:2017-10-23 18:32:19
【问题描述】:

我正在尝试抓取一个网站:http://www.vehiculo-robado.com,但返回给我的是:

error:       null
statusCode:  200
body:        <html style="height:100%"><head><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"><meta name="format-detection" content="telephone=no"><meta name="viewport" content="initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"></head><body style="margin:0px;height:100%"><iframe src="/_Incapsula_Resource?CWUDNSAI=9&xinfo=6-31980899-0%202NNN%20RT%281508782951589%204%29%20q%280%20-1%20-1%20-1%29%20r%280%20-1%29%20B12%284%2c315%2c0%29&incident_id=874000030218433631-157072954141311030&edet=12&cinfo=04000000" frameborder=0 width="100%" height="100%" marginheight="0px" marginwidth="0px">Request unsuccessful. Incapsula incident ID: 874000030218433631-157072954141311030</iframe></body></html>

网络有 html...

这是我抓取网页的中间件:

const request = require('request');

function webScraped(req,res,next){      
    const url = `http://www.vehiculo-robado.com`
    req.webParsed = function webToScrape (callback){ 
        request(url, function(error, response, body){
            console.log('error:', error);
            console.log('statusCode:', response && response.statusCode);
            console.log('body =========>', body)
            return callback(false, body);
        })
    }
    next()
}

module.exports = webScraped

我尝试过使用其他网站,例如 Google,它返回的 html 很好。 我不知道我做错了什么。

【问题讨论】:

    标签: node.js npm web-scraping npm-request


    【解决方案1】:

    该网站 (vehiculo-robado) 正在使用名为 SiteLock 的抓取保护服务。这就是为什么它拒绝您的请求并向您发送基本上是一个空的 html。这是我得到的回复:

    <html style="height:100%">
    
    <head>
      <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
      <meta name="format-detection" content="telephone=no">
      <meta name="viewport" content="initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    </head>
    
    <body style="margin:0px;height:100%"><iframe
        src="/_Incapsula_Resource?SWUDNSAI=9&xinfo=3-7455753-0%200NNN%20RT%281550759526831%201%29%20q%280%20-1%20-1%20-1%29%20r%280%20-1%29%20B12%284%2c316%2c0%29%20U10000&incident_id=511001260010653929-37058068785072099&edet=12&cinfo=04000000"
        frameborder=0 width="100%" height="100%" marginheight="0px" marginwidth="0px">Request unsuccessful. Incapsula
        incident ID:
        511001260010653929-37058068785072099</iframe></body>
    
    </html>
    

    通过将您的请求塑造成普通用户的浏览器请求应该可以绕过它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-12
      相关资源
      最近更新 更多