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

[V 币感谢] headless 浏览器是否有办法抓取网页中的 ajax 请求,并 js 模拟发送么

  •  
  •   akmonde · 2019-01-15 18:00:35 +08:00 · 2251 次点击
    这是一个创建于 1898 天前的主题,其中的信息可能已经有所发展或是发生改变。

    RT,最近玩 scrapy 有这方面的需求,不知道有没有办法以 middlewares 的手段去抓取 JS 标签里的 ajax 请求,并模拟发送。 是否只能手动提取,再组合参数发送?

    在线等大佬解答,感谢!!

    6 条回复    2019-01-17 13:44:37 +08:00
    epkT6QJ3RSaz6AnJ
        2
    epkT6QJ3RSaz6AnJ  
       2019-01-15 18:21:49 +08:00
    目前只想到可以搞个 polyfill,然后拦截
    cy97cool
        3
    cy97cool  
       2019-01-15 22:06:54 +08:00
    hookajax 以及 fetch 的 polyfill 就能在 js 层面把请求拦下来了
    不过浏览器都能控制的话 为啥不直接看浏览器开发人员工具提供的 network 呢
    wangtao7
        4
    wangtao7  
       2019-01-15 22:57:18 +08:00
    akmonde
        5
    akmonde  
    OP
       2019-01-17 13:37:44 +08:00
    @epkT6QJ3RSaz6AnJ 您的意思是拦截器监控再复现?但是我在随机爬行某个网站时不一定能触发该 js 函数,我这算是黑盒,白盒的应该不太适用。
    akmonde
        6
    akmonde  
    OP
       2019-01-17 13:44:37 +08:00
    @cy97cool
    @wangtao7
    感谢两位的回复,两位说的都是拦截器吧,不过我黑盒爬虫去爬不一定能触发 ajax,靠这个拦截复现不太现实。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5006 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 09:47 · PVG 17:47 · LAX 02:47 · JFK 05:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.