2
http://en.wikipedia.org/wiki/List_of_cities_in_China提取维基百科
所有城市我想提取所有的城市名称,如下图所示:
我用下面的代码(仅用于提取一个字段),其中XPath是副本from chrome
from lxml import html
import requests
page = requests.get('http://en.wikipedia.org/wiki/List_of_cities_in_China')
tree = html.fromstring(page.text)
huabeiTree=tree.xpath('//*[@id="mw-content-text"]/table[3]/tbody/tr[1]/td[1]/a/text()')
print huabeiTree
什么都没有出现。
我的最终目标是提取列表中的所有城市,我可以知道如何实现这一目标吗?
你的目标是什么!如果你想获得中国的所有城市,有一个更简单的方法来做到这一点 – user3378649 2014-10-30 07:26:25