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

请问如何用 python 抓这一类数据

  •  
  •   kingmo888 · 2016-01-20 16:58:26 +08:00 · 2116 次点击
    这是一个创建于 3032 天前的主题,其中的信息可能已经有所发展或是发生改变。

    http://www.swsindex.com/idx0120.aspx?columnid=8832

    网页源码中没有需要的数据,数据是 js 获取的。

    15 条回复    2016-01-27 15:45:56 +08:00
    hcwhan
        1
    hcwhan  
       2016-01-20 17:17:34 +08:00
    crab
        2
    crab  
       2016-01-20 17:48:34 +08:00
    URL : http://www.swsindex.com/handler.aspx
    Method : POST
    DATA : tablename=swzs&key=L1&p=1&where= L1 in('801010','801020','801030','801040','801050','801060','801070','801080','801090','801100','801110','801120','801130','801140','801150','801160','801170','801180','801190','801200','801210','801220','801230','801710','801720','801730','801740','801750','801760','801770','801780','801790','801880','801890')&orderby=&fieldlist=L1,L2,L3,L4,L5,L6,L7,L8,L11&pagecount=28&timed=1453283369415
    kingmo888
        3
    kingmo888  
    OP
       2016-01-20 22:18:01 +08:00
    @crab 我打开回帖的链接,提示错误。
    这个 post 方法是怎么用的哈?
    kingmo888
        4
    kingmo888  
    OP
       2016-01-20 22:19:12 +08:00
    @hcwhan 这个帖子我在查资料时也搜到了。试了里面的方法,或许是能力有限,没能成功。无奈才来求助。看看有没有朋友整一个实例。
    crab
        5
    crab  
       2016-01-20 22:48:27 +08:00
    @kingmo888 你打开链接是 get 啊,肯定不能。就是 post 下面那些数据到那链接,就会返回你要的内容了。
    kingmo888
        6
    kingmo888  
    OP
       2016-01-23 16:13:06 +08:00
    @crab 我在 IE11 下,使用网络跟踪,得到一个 POST 请求:
    tablename=V_Report&key=id&p=1&where=BargainDate = (select max(bargaindate) from SwIndexQuotation where swindexcode='801003' ) and type='day' and swindexcode in ('801010','801020','801030','801040','801050','801060','801070','801080','801090','801100','801110','801120','801130','801140','801150','801160','801170','801180','801190','801200','801210','801220','801230','801710','801720','801730','801740','801750','801760','801770','801780','801790','801880','801890')&orderby=swindexcode asc,BargainDate_1&fieldlist=SwIndexCode,SwIndexName,BargainDate,CloseIndex,BargainAmount,Markup,TurnoverRate,PE,PB,MeanPrice,BargainSumRate,NegotiablesShareSum,NegotiablesShareSum2,DP&pagecount=28&timed=1453536458577



    -----
    我构造了一个 post 的 URL ,访问时需要有登录权限。
    你的那个 post ,在访问时也是需要登录权限的。
    crab
        7
    crab  
       2016-01-23 16:19:39 +08:00
    @kingmo888 测试完全可以
    ![QQ 截图 20160123162012.png]( https://ooo.0o0.ooo/2016/01/23/56a338369ae0b.png)
    lijsh
        8
    lijsh  
       2016-01-24 01:40:27 +08:00
    用 Post 加数据肯定没问题的,浏览器都是这么取的,除非要伪造 UA 。

    参考这篇文章 http://zhuanlan.zhihu.com/xlz-d/20430122
    kingmo888
        9
    kingmo888  
    OP
       2016-01-25 20:26:13 +08:00
    @crab 请问如何实现的?!确实是需要的数据
    kingmo888
        10
    kingmo888  
    OP
       2016-01-25 22:12:35 +08:00
    @lijsh 抱歉看到后第一时间去学习了没能即时回复。看了一晚上没看明白。第一次接触 python 爬虫。当然,小白不是理由。我仍在努力。
    lijsh
        11
    lijsh  
       2016-01-26 14:36:35 +08:00
    @kingmo888 你看原页面是用$.ajax 方法 post 一个"tablename=swzs&key=L1&p="+(pageindx+1)+"... 这样的字符串过去获取 json 结果的;用 Python 的话思路也类似,用 requests 的 post 方法, data 参数要把上面这个字符串转换成 dict ;我之前测过,可以得到结果
    kingmo888
        12
    kingmo888  
    OP
       2016-01-26 16:48:04 +08:00
    @lijsh 你好,像这种“ where swindexcode='801003' ) and type='”条件怎么转化为 dict 呢。
    如果能提供一份例子就太好了。
    mikezhang0515
        13
    mikezhang0515  
       2016-01-26 17:11:54 +08:00
    @crab 请问如何跟踪到这个数据的
    lijsh
        14
    lijsh  
       2016-01-27 12:18:43 +08:00
    @kingmo888 https://gist.github.com/lijsh/7d3911dfe19c01941b45 新学 Python ,方法比较原始,能用就行。
    kingmo888
        15
    kingmo888  
    OP
       2016-01-27 15:45:56 +08:00
    @lijsh 非常感谢!原来是这样的用法。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3625 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 00:45 · PVG 08:45 · LAX 17:45 · JFK 20:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.