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
Yc1992
V2EX  ›  Python

求问: scrapy 解析 js 有什么好的方案?

  •  
  •   Yc1992 ·
    bufrr · 2015-10-24 18:59:50 +08:00 · 2571 次点击
    这是一个创建于 3114 天前的主题,其中的信息可能已经有所发展或是发生改变。
    现在只能解析静态的网页内容,想请教各位 scrapy 对于动态的内容有什么好的方案?
    12 条回复    2015-10-25 12:39:07 +08:00
    bdbai
        1
    bdbai  
       2015-10-24 19:41:21 +08:00 via iPhone
    简单的 AJAX 分析一下请求即可,涉及到算法的可以尝试将 JavaScript 代码用 Python 表达。实在懒的话直接操控浏览器,不过效率很低。
    est
        2
    est  
       2015-10-24 19:42:59 +08:00
    pyexecjs phantomjs
    Victor215
        3
    Victor215  
       2015-10-24 20:00:38 +08:00
    千年老问题,快成月经贴了……楼上的方法是通用的。
    ljbha007
        4
    ljbha007  
       2015-10-24 20:20:21 +08:00
    有个办法是遇到 script 标签和 js 文件 就用正则匹配 url 这样不用去管程序逻辑到底是怎样的
    Yc1992
        5
    Yc1992  
    OP
       2015-10-24 21:17:51 +08:00
    @ljbha007 有些情况这样可以,但是很多情况比如把链接放到 function 中或者 onload 这种情况就不行了
    Yc1992
        6
    Yc1992  
    OP
       2015-10-24 21:18:17 +08:00
    @bdbai 感谢回复,我研究下~
    Yc1992
        7
    Yc1992  
    OP
       2015-10-24 21:19:05 +08:00
    @est 谢谢
    ljbha007
        8
    ljbha007  
       2015-10-24 21:46:49 +08:00
    @Yc1992 那你把 onload 也加上啊
    leavic
        9
    leavic  
       2015-10-24 23:36:05 +08:00
    ajax 基本都可以查到实际查询的位置,查处后用 request 单独请求一次这个数据就行。
    PythonAnswer
        10
    PythonAnswer  
       2015-10-25 00:33:05 +08:00
    不要效率的话,模拟浏览器也没啥。对服务器也温柔。
    gaotongfei
        11
    gaotongfei  
       2015-10-25 09:31:21 +08:00 via iPad
    selenium
    berry10086
        12
    berry10086  
       2015-10-25 12:39:07 +08:00
    selenium + phantomjs
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2390 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 14:55 · PVG 22:55 · LAX 07:55 · JFK 10:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.