fghfjujiber
V2EX  ›  问与答

在写 PHP 爬虫,因为 file_get_contents 卡死了,怎么办?

  •  
  •   fghfjujiber · Jul 7, 2015 · 3988 views
    This topic created in 3988 days ago, the information mentioned may be changed or developed.

    因为部分页面是ajax动态加载的,所以要用file_get_contents获取json数据。

    8 replies    2015-07-07 18:12:16 +08:00
    dalaomj
        1
    dalaomj  
       Jul 7, 2015
    用fsockopen或者curl,可以自定义的元素更多。file_get_contents连UA都是在php.ini里定义的。
    b821025551b
        2
    b821025551b  
       Jul 7, 2015
    超时,or换curl
    hjxx
        3
    hjxx  
       Jul 7, 2015
    fghfjujiber
        4
    fghfjujiber  
    OP
       Jul 7, 2015
    好的我试一试
    tabris17
        5
    tabris17  
       Jul 7, 2015
    通过 stream_context参数可以设置超时
    yeyeye
        6
    yeyeye  
       Jul 7, 2015
    @dalaomj file_get_contents可以在用 到时候设置UA等其他请求参数
    lincanbin
        7
    lincanbin  
       Jul 7, 2015
    用curl。
    lshero
        8
    lshero  
       Jul 7, 2015
    @dalaomj stream_context_create挺有用的file_get_contents时可以配合使用
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1245 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 17:16 · PVG 01:16 · LAX 10:16 · JFK 13:16
    ♥ Do have faith in what you're doing.