pyhon/numpy/pandas(十二)-xml

from lxml.html import parse
import urllib.request
parsed=parse(urllib.request.urlopen('http://finance.sina.com.cn/stock/'))
doc=parsed.getroot()
print (doc)

<Element html at 0x54db9f8>
links=doc.findall('.//a')
links[:3]

[<Element a at 0x55fe5e8>, <Element a at 0x55fe868>, <Element a at 0x55fe6d8>]
urls=[lnk.get('href') for lnk in doc.findall('.//a')]
urls[-10:]

['http://corp.sina.com.cn/chn/',
 'http://corp.sina.com.cn/eng/',
 'http://emarketing.sina.com.cn/',
 'http://www.sina.com.cn/contactus.html',
 'http://corp.sina.com.cn/chn/sina_job.html',
 'http://www.sina.com.cn/intro/lawfirm.shtml',
 'http://english.sina.com',
 'https://login.sina.com.cn/signup/signup.php',
 'http://help.sina.com.cn/',
 'http://corp.sina.com.cn/chn/copyright.html']
tables=doc.findall('.//table')
call=tables[1]
rows=call.findall('.//tr')

def _unpack(row,kind='td'):
    elts=row.findall('.//%s' % kind)
    return [val.text_content() for val in elts]
_unpack(rows[0],kind='td')

['行业涨幅', '行业跌幅', '行业流入', '行业流出']
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

海持Alvin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值