免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2501 | 回复: 3
打印 上一主题 下一主题

已解决 [复制链接]

论坛徽章:
1
程序设计版块每日发帖之星
日期:2015-11-25 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-12-04 00:19 |只看该作者 |倒序浏览
本帖最后由 micrchaoo 于 2015-12-22 19:20 编辑

已解决

论坛徽章:
1
操作系统版块每日发帖之星
日期:2016-06-12 06:20:00
2 [报告]
发表于 2015-12-04 15:33 |只看该作者
本帖最后由 yakczh_cu 于 2015-12-04 15:34 编辑

  1. import lxml.html

  2. url='http://www.icbc.com.cn/ICBCDynamicSite2/other/rmbdeposit.aspx'

  3. doc = lxml.html.parse(url)
  4. table = doc.xpath('//table[@frame="border"]')
  5. if table[0]:
  6.         for row in table[0].xpath('.//tr'):
  7.                 cells = row.xpath('.//th') + row.xpath('.//td')
  8.                 print()
  9.                 for cell in cells:
  10.                         # The individual cell's content
  11.                         content = cell.text_content() #.encode("utf8")
  12.                         print(content,end="\t")
复制代码

评分

参与人数 2信誉积分 +15 收起 理由
micrchaoo + 5 很给力!
substr函数 + 10 赞一个!

查看全部评分

论坛徽章:
1
程序设计版块每日发帖之星
日期:2015-11-25 06:20:00
3 [报告]
发表于 2015-12-04 23:13 |只看该作者
十分感谢
这个网址我也找到了办法
但我从工行官网上点人个金融的存贷款利率表网页,你这个不一样,里面连日期列表都没有,感觉无从下手

论坛徽章:
0
4 [报告]
发表于 2015-12-05 02:29 |只看该作者
本帖最后由 majiayang2012 于 2015-12-05 02:31 编辑

回复 3# micrchaoo
  1. #-*-conding=utf-8 -*-
  2. import urllib2
  3. import urllib
  4. import lxml.html
  5. import re
  6. import json
  7. import sys

  8. reload(sys)
  9. sys.setdefaultencoding( "utf-8" )

  10. results={}
  11. url ="http://www.yinhang.com/rate/saving/3_1"
  12. request=urllib2.Request(url)
  13. response=urllib2.urlopen(request).read()
  14. for option in lxml.html.fromstring(response).xpath('//*[@id="begin_time"]/option/@value'):
  15.         values={'begin_time':option}
  16.         if len(values['begin_time'])>2:
  17.                 data=urllib.urlencode(values)
  18.                 request_=urllib2.Request(url,data)
  19.                 response_=urllib2.urlopen(request_).read()
  20.                 results[values['begin_time']]=lxml.html.fromstring(response_).xpath("//div[@class='xiangmu mg_top10']/ul/li/text()")
  21. with open('resutls.json','wb') as f:
  22.         f.write(json.dumps(results, ensure_ascii = False,encoding='ascii',indent = 4,separators = (',',':')))
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP