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

请教,为什么在服务器上 wget https://tieba.baidu.com 不行?

  •  
  •   gdtv · 2016-08-12 09:55:57 +08:00 · 4214 次点击
    这是一个创建于 2826 天前的主题,其中的信息可能已经有所发展或是发生改变。
    注意是 https 不是 http ,别问为什么要用 https ,不在此贴讨论范围。
    试过阿里云服务器和国外的 vultr 服务器,结果一样。

    wget https://tieba.baidu.com
    --2016-08-12 09:50:44-- https://tieba.baidu.com/
    Resolving tieba.baidu.com... 180.97.104.41, 180.97.104.40
    Connecting to tieba.baidu.com|180.97.104.41|:443...
    结果是:
    failed: Connection timed out

    ---------------------------------------

    $result = file_get_contents('https://tieba.baidu.com');
    这个 php 命令在我电脑上(windows+apache+php)成功,但在服务器上(centos6+apache+php)就是:
    failed to open stream: Connection timed out

    -----------------------------------

    这是怎么回事呢?
    第 1 条附言  ·  2016-08-12 11:10:35 +08:00
    不好意思,我补充说一下:

    目标:抓取百度贴吧的手机版本页面,注意是手机版本

    抓取的 url : http://tieba.baidu.com/m?ie=utf-8&kw=%E6%9C%BA%E6%A2%B0%E9%94%AE%E7%9B%98%E4%BA%A4%E6%98%93&pn=0

    命令:
    curl 'http://tieba.baidu.com/m?ie=utf-8&kw=%E6%9C%BA%E6%A2%B0%E9%94%AE%E7%9B%98%E4%BA%A4%E6%98%93&pn=0' -I -H 'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1'

    返回结果:
    Location: https://tieba.baidu.com/f?ie=utf-8&kw=%E6%9C%BA%E6%A2%B0%E9%94%AE%E7%9B%98%E4%BA%A4%E6%98%93&pn=0

    继续抓取 302 转向的地址:
    curl 'https://tieba.baidu.com/f?ie=utf-8&kw=%E6%9C%BA%E6%A2%B0%E9%94%AE%E7%9B%98%E4%BA%A4%E6%98%93&pn=0' -I -H 'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1'

    返回结果:
    time out
    12 条回复    2016-08-12 13:48:45 +08:00
    gdtv
        2
    gdtv  
    OP
       2016-08-12 10:45:24 +08:00
    aprikyblue
        3
    aprikyblue  
       2016-08-12 10:50:29 +08:00 via Android
    贴吧有上 https 吗。。。
    443 端口都是关的。。
    bjzhou1990
        4
    bjzhou1990  
       2016-08-12 10:51:22 +08:00
    @gdtv tieba 的 https 我浏览器都打不开,别说 wget 了。。。
    Infernalzero
        5
    Infernalzero  
       2016-08-12 10:53:14 +08:00
    curl 'http://tieba.baidu.com/' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: zh-CN,zh;q=0.8' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.63 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Connection: keep-alive' --compressed


    看了下,其实其他 header 都不需要,只要 UA 有就可以了
    ragnaroks
        6
    ragnaroks  
       2016-08-12 10:54:11 +08:00
    wget https://tieba.baidu.com --user-agent="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092416 Firefox/3.0.3" --no-check-certificate

    测试正常,话说我这访问 https://tieba.baidu.com 直接超时,只能访问 http 的
    Infernalzero
        7
    Infernalzero  
       2016-08-12 10:55:37 +08:00
    看错, LZ 说的是 wget ,忽略我说的吧
    gdtv
        8
    gdtv  
    OP
       2016-08-12 11:11:19 +08:00
    @Infernalzero curl 也行,我补充了帖子,请再帮忙看一下,谢谢
    gdtv
        9
    gdtv  
    OP
       2016-08-12 11:11:59 +08:00
    @aprikyblue
    @bjzhou1990
    @ragnaroks
    已补充帖子,请再帮忙看一下,谢谢
    nsgit
        10
    nsgit  
       2016-08-12 11:28:22 +08:00
    贴吧 443 端口都没开,你到哪去 curl ?
    workspace
        11
    workspace  
       2016-08-12 12:19:27 +08:00
    我表示直接 wget 第一个地址就能下载下来,测试机: bw vps
    msg7086
        12
    msg7086  
       2016-08-12 13:48:45 +08:00
    $ wget https://tieba.baidu.com
    --2016-08-12 01:48:14-- https://tieba.baidu.com/
    正在解析主机 tieba.baidu.com (tieba.baidu.com)... 103.235.46.140, 103.235.46.139
    正在连接 tieba.baidu.com (tieba.baidu.com)|103.235.46.140|:443... 已连接。
    已发出 HTTP 请求,正在等待回应... 200 OK
    长度:未指定 [text/html]
    正在保存至: “ index.html.1 ”

    index.html.1 [ <=> ] 167.66K 95.4KB/s in 1.8s

    2016-08-12 01:48:17 (95.4 KB/s) - “ index.html.1 ” 已保存 [171688]

    自己看看解析出来的 IP 。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3782 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:44 · PVG 18:44 · LAX 03:44 · JFK 06:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.