firhome
V2EX  ›  Node.js

douban 的 www 域名 request 抓不到吗?

  •  
  •   firhome · Apr 29, 2014 · 3637 views
    This topic created in 4434 days ago, the information mentioned may be changed or developed.
    在cnodejs 上发过,没人回复,再到这里问下.


    看了很多例子都是拿douban做爬虫的例子..

    然后我也试试.

    发现
    request('http://movie.douban.com/') 有用

    request('http://www.douban.com/') 没用

    是什么原因呢?
    8 replies    2014-04-29 18:04:29 +08:00
    khowarizmi
        1
    khowarizmi  
       Apr 29, 2014   ❤️ 1
    var request = require('request');
    request.get({
    url: 'http://www.douban.com',
    headers: {
    'User-Agent': 'request'
    }
    }, function(err, res, body){
    console.log(body)
    })
    rails3
        2
    rails3  
       Apr 29, 2014   ❤️ 1
    require 'net/http'
    Net::HTTP.get('www.douban.com','/')

    毫无鸭梨
    firhome
        3
    firhome  
    OP
       Apr 29, 2014
    @rails3 能说说为什么吗.
    firhome
        4
    firhome  
    OP
       Apr 29, 2014
    @khowarizmi 能告诉我为什么吗? www 的不行
    dorentus
        5
    dorentus  
       Apr 29, 2014
    @rails3 你这明明是 ruby 的代码……


    @firhome 什么叫「www 的不行」,有什么错误信息么?
    khowarizmi
        6
    khowarizmi  
       Apr 29, 2014   ❤️ 1
    @firhome 豆瓣认为你是爬虫,直接爬就403了呗 。加上user-agent,装成浏览器。。
    firhome
        7
    firhome  
    OP
       Apr 29, 2014
    @khowarizmi 感谢, 那么我以后怎么判断/分析 是这个原因呢?
    YouXia
        8
    YouXia  
       Apr 29, 2014
    @firhome 可以参考下HTTP协议的状态码。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   829 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 21:10 · PVG 05:10 · LAX 14:10 · JFK 17:10
    ♥ Do have faith in what you're doing.