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

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

  •  
  •   iam36 · 2015-04-08 14:52:38 +08:00 · 6062 次点击
    这是一个创建于 3305 天前的主题,其中的信息可能已经有所发展或是发生改变。
    web页中使用了javasript进行翻页跳转,如何通过python获取有效的URL?

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

    学抓页面的从来都不去学习下web入门知识么。。。。。。。。
    ljcarsenal
        3
    ljcarsenal  
       2015-04-08 15:39:09 +08:00
    全民抓取啊。。。。具体情况具体分析,有些链接是有规律的,自己拼接url。。不如你把连接贴出来
    iam36
        4
    iam36  
    OP
       2015-04-08 16:00:56 +08:00
    动作:
    <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  
       2015-04-08 20:16:43 +08:00
    phantomjs算了
    Slienc7
        6
    Slienc7  
       2015-04-08 21:07:50 +08:00 via Android
    找个网站,看看JavaScript和html入门要不了多久
    facat
        7
    facat  
       2015-04-08 23:22:46 +08:00
    @iam36 看你贴的这段代码,你直接抓取 http://www.你抓取的网站.com/app/get.action?weekflag="你要的内容"
    aaaa007cn
        8
    aaaa007cn  
       2015-04-09 00:13:51 +08:00
    @iam36
    最无脑的方法肯定是开着浏览器的开发者工具记录请求
    然后观察点击后浏览器发出的请求

    @facat
    这是个 form
    还得考虑 dateStr、channelId、channelName 是不是在 form 中
    是 GET 还是 POST
    v5mark
        9
    v5mark  
       2015-04-09 11:38:38 +08:00
    phantomjs +1
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2685 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 16:03 · PVG 00:03 · LAX 09:03 · JFK 12:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.