数据采集、提取与处理全攻略
1. 数据采集与提取
1.1 XPath 和 CSS 选择器的运用
在数据采集过程中,XPath 和 CSS 选择器是强大的工具。例如,若要选择所有类名为 “planet” 的 <tr> 元素,可使用如下代码:
[(v, v.xpath("@name")) for v in tree.cssselect('tr.planet')]
执行该代码后,输出结果如下:
[(<Element tr at 0x10d3a2278>, ['Mercury']),
(<Element tr at 0x10c16ed18>, ['Venus']),
(<Element tr at 0x10e445688>, ['Earth']),
(<Element tr at 0x10e477228>, ['Mars']),
(<Element tr at 0x10e477408>, ['Jupiter']),
(<Element tr at 0x10e477458>, ['Saturn']),
(<Element tr at 0x10e4774a8>, ['Uranus']),
(<Element tr at 0x10e4774f8>, ['Neptune']),
(<Element tr at 0x10e477548>, ['P
超级会员免费看
订阅专栏 解锁全文
259

被折叠的 条评论
为什么被折叠?



