heloman
V2EX  ›  问与答

用 requests 抓取 ngacn.cc 页面内容 error

  •  
  •   heloman · Oct 14, 2015 · 2907 views
    This topic created in 3874 days ago, the information mentioned may be changed or developed.

    打算抓取 http://bbs.ngacn.cc/thread.php?fid=-7&page=1 里面的帖子,找出热点帖子。 python 写了脚本,但运行时总是出错。

    代码如下:

    https://gist.github.com/anonymous/99ef5fb95bd8e4c72f1d

    抓取分两步,第一次直接抓的页面里面有 js 在 url 上附加一个 rand 参数之后再次加载,但第二次抓取总是报错:

    https://gist.github.com/anonymous/2ea6d51690926641501f

    6 replies    2015-10-15 09:54:40 +08:00
    ksupertu
        1
    ksupertu  
       Oct 14, 2015 via iPad
    Phantomjs
    liiihhhh
        2
    liiihhhh  
       Oct 14, 2015
    heloman
        3
    heloman  
    OP
       Oct 14, 2015
    @liiihhhh 多谢! 看到 lite=xml 可以直接获得 xml ,但是查看 fid=-7 的页面总是要有一次再次加载的过程,手动构造了加 rand 的 url 但还是 get 数据出错,这个怎么破?
    比如
    http://bbs.ngacn.cc/thread.php?fid=7&lite=xml&page=1&rand=996
    这个可以直接访问
    但是
    http://bbs.ngacn.cc/thread.php?fid=-7&lite=xml&page=1&rand=996
    这个 url 已经附加了 rand 参数,但还是报错
    heloman
        4
    heloman  
    OP
       Oct 14, 2015
    @ksupertu 这个好牛!似乎太复杂的样子~ 我现在已经附加参数模拟 js 行为了,应该和用 Phantomjs 效果一致吧,但还是出错
    liiihhhh
        5
    liiihhhh  
       Oct 15, 2015
    @heloman 加 rand=996 这个参数是干嘛的? http://bbs.ngacn.cc/thread.php?fid=7&lite=xml&page=1&rand=996 可以获得数据啊
    heloman
        6
    heloman  
    OP
       Oct 15, 2015
    @liiihhhh 试试 fid=-7 , js 里这个分两步加载,第二步的请求里附加了 rand
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   844 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 21:34 · PVG 05:34 · LAX 14:34 · JFK 17:34
    ♥ Do have faith in what you're doing.