推荐学习书目
› 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 · Jan 20, 2016 · 3040 views
    This topic created in 3941 days ago, the information mentioned may be changed or developed.

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

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

    15 replies  •  2016-01-27 15:45:56 +08:00
    crab
    crab
    Jan 20, 2016
    2
    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
    kingmo888
    OP
    Jan 20, 2016
    3
    @crab 我打开回帖的链接,提示错误。
    这个 post 方法是怎么用的哈?
    kingmo888
    kingmo888
    OP
    Jan 20, 2016
    4
    @hcwhan 这个帖子我在查资料时也搜到了。试了里面的方法,或许是能力有限,没能成功。无奈才来求助。看看有没有朋友整一个实例。
    crab
    crab
    Jan 20, 2016
    5
    @kingmo888 你打开链接是 get 啊,肯定不能。就是 post 下面那些数据到那链接,就会返回你要的内容了。
    kingmo888
    kingmo888
    OP
    Jan 23, 2016
    6
    @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
    crab
    Jan 23, 2016
    7
    @kingmo888 测试完全可以
    ![QQ 截图 20160123162012.png]( https://ooo.0o0.ooo/2016/01/23/56a338369ae0b.png)
    lijsh
    lijsh
    Jan 24, 2016
    8
    用 Post 加数据肯定没问题的,浏览器都是这么取的,除非要伪造 UA 。

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