V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
linhanqiu
V2EX  ›  Python

Python 爬虫

  •  1
     
  •   linhanqiu · 2018-01-02 13:52:17 +08:00 · 2296 次点击
    这是一个创建于 2277 天前的主题,其中的信息可能已经有所发展或是发生改变。

    想问一下大家 python 的 urllib 库怎么爬取跳转的链接, 我大概想了跳转链接分两类,一种是直接跳转:304 另一种是响应 200,然后自动 js 跳转的, 想问一下,是怎么实现的,需要请求 js 的 url 吗 ps:python3 环境下

    12 条回复    2018-01-05 10:34:16 +08:00
    p2pCoder
        1
    p2pCoder  
       2018-01-02 13:58:33 +08:00
    js 自动跳转的,你请求到包含 js 页面的就可以了
    WoodenRobot
        2
    WoodenRobot  
       2018-01-02 14:56:44 +08:00
    为什么不用 Requests?
    Flobit
        3
    Flobit  
       2018-01-02 15:24:51 +08:00
    胶水语言,不要局限在一个库里面,不行就换,多试试其他的。
    dirls
        4
    dirls  
       2018-01-02 15:26:38 +08:00
    1# 正解
    wh01096045
        5
    wh01096045  
       2018-01-02 17:24:16 +08:00
    你也可以分析 js,得到跳转的 url,然后请求
    ray8888
        6
    ray8888  
       2018-01-02 17:42:37 +08:00 via iPhone
    为什么不用 scrapy
    Ginson
        7
    Ginson  
       2018-01-02 17:51:21 +08:00
    我一般是分析 JS,拿到跳转后的链接;或者直接用能执行 JS 的库去请求,比如 selenium webdriver
    linhanqiu
        8
    linhanqiu  
    OP
       2018-01-04 22:30:20 +08:00
    @p2pCoder
    但是请求到的是包含 js 的 html 文件,并没有跳转
    linhanqiu
        9
    linhanqiu  
    OP
       2018-01-04 22:31:33 +08:00
    @WoodenRobot Requests 怎么能够自动跳转,之前看到 urllib 库可以获取跳转后的链接,不知道 requests 可不可以
    linhanqiu
        10
    linhanqiu  
    OP
       2018-01-04 22:32:08 +08:00
    @wh01096045 好吧,我也打算这么做
    linhanqiu
        11
    linhanqiu  
    OP
       2018-01-04 22:33:19 +08:00
    @Ginson 好的,
    WoodenRobot
        12
    WoodenRobot  
       2018-01-05 10:34:16 +08:00
    @linhanqiu 直接重定向的 requests 可以自动实现重定向,在返回数据中获取重定向后的 URL。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1192 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 106ms · UTC 23:10 · PVG 07:10 · LAX 16:10 · JFK 19:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.