V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
happydebug
V2EX  ›  问与答

这个网站是怎么反爬取的鸭

  •  
  •   happydebug · 2021-03-18 11:12:43 +08:00 · 1352 次点击
    这是一个创建于 1145 天前的主题,其中的信息可能已经有所发展或是发生改变。
    4 条回复    2021-03-18 13:32:16 +08:00
    crab
        1
    crab  
       2021-03-18 12:20:53 +08:00
    F12 有 2 个地方的 debugger 设置 never pause here
    happydebug
        2
    happydebug  
    OP
       2021-03-18 13:00:15 +08:00 via iPhone
    @crab 这个我知道,但无法实现抓取
    xingshu1990
        3
    xingshu1990  
       2021-03-18 13:12:04 +08:00
    通常这类网站是 JS 渲染出来的内容,另外有加密过,参考裁判文书网之类的网站,就是不给你爬虫爬。
    cmostuor
        4
    cmostuor  
       2021-03-18 13:32:16 +08:00   ❤️ 1
    浏览器 F12 调试模式 -> 网络 -> 找到网站请求的 url 右键 -> 复制->复制为 cURL(bash) 会得到这样的代码

    curl 'http://www.chinadrugtrials.org.cn/clinicaltrials.searchlistdetail.dhtml?id=eb6173d1faf4447bb8e69aaca2547d09' \
    -H 'Connection: keep-alive' \
    -H 'Pragma: no-cache' \
    -H 'Cache-Control: no-cache' \
    -H 'DNT: 1' \
    -H 'Upgrade-Insecure-Requests: 1' \
    -H 'User-Agent: *****' \
    -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
    -H 'Referer: http://www.chinadrugtrials.org.cn/clinicaltrials.searchlistdetail.dhtml?id=eb6173d1faf4447bb8e69aaca2547d09' \
    -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6' \
    -H 'Cookie: *****' \
    --compressed \
    --insecure
    然后到 bash 里粘贴运行 发现拿到的页面数据是只是加密的 js, 也就意味着网页是客户端动态渲染的. 想抓取 那么得在爬数据前用 Selenium WebDriver 这类浏览器自动化的工具或浏览器源码定制开发渲染层或直接基于这样的工具或浏览器源码开发爬虫, 基于浏览器自动化工具开发爬虫最快.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   972 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 20:30 · PVG 04:30 · LAX 13:30 · JFK 16:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.