推荐学习书目
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
iam36
V2EX  ›  Python

python 抓取页面使用 javascript 做跳转,该如何获取有效 URL?

  •  
  •   iam36 · Apr 8, 2015 · 7021 views
    This topic created in 4075 days ago, the information mentioned may be changed or developed.
    web页中使用了javasript进行翻页跳转,如何通过python获取有效的URL?

    搜索了半天不得要领
    9 replies    2015-04-09 11:38:38 +08:00
    facat
        1
    facat  
       Apr 8, 2015
    什么形式的跳转?是直接写在js里面,还是用js取回地址后跳转?
    est
        2
    est  
       Apr 8, 2015
    月经问题了。

    学抓页面的从来都不去学习下web入门知识么。。。。。。。。
    ljcarsenal
        3
    ljcarsenal  
       Apr 8, 2015
    全民抓取啊。。。。具体情况具体分析,有些链接是有规律的,自己拼接url。。不如你把连接贴出来
    iam36
        4
    iam36  
    OP
       Apr 8, 2015
    动作:
    <a href="javascript:query('prevWeek');" class="prev">上一周</a>

    JS:

    function query(weekflag) {
    var channelId = document.getElementById("channelId");
    var dateStr = document.getElementById("dateStr");
    if (dateStr.value == null || dateStr.value == '') {
    alert("请选择时间.");
    return false;
    }
    if (channelId.value == null || channelId.value == '') {
    alert("请选择类型.");
    return false;
    }
    var channelName = channelId.options[channelId.selectedIndex].text;
    document.getElementById("channelName").value=channelName;
    form1.action = "/app/get.action?weekflag="+weekflag;
    form1.submit();


    不会写网页 ,连调试都不会,道理上应该是确定weekflag的内容,再和"/app/get.action?weekflag="串起来提交即可。

    确实没搞定
    mengskysama
        5
    mengskysama  
       Apr 8, 2015
    phantomjs算了
    Slienc7
        6
    Slienc7  
       Apr 8, 2015 via Android
    找个网站,看看JavaScript和html入门要不了多久
    facat
        7
    facat  
       Apr 8, 2015
    @iam36 看你贴的这段代码,你直接抓取 http://www.你抓取的网站.com/app/get.action?weekflag="你要的内容"
    aaaa007cn
        8
    aaaa007cn  
       Apr 9, 2015
    @iam36
    最无脑的方法肯定是开着浏览器的开发者工具记录请求
    然后观察点击后浏览器发出的请求

    @facat
    这是个 form
    还得考虑 dateStr、channelId、channelName 是不是在 form 中
    是 GET 还是 POST
    v5mark
        9
    v5mark  
       Apr 9, 2015
    phantomjs +1
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3159 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 12:48 · PVG 20:48 · LAX 05:48 · JFK 08:48
    ♥ Do have faith in what you're doing.