它确实得到了Link1的坐标,但是同样的代码得到了另一个国家的坐标…为什么?(一年前效果不错)
link1='http://en.wikipedia.org/wiki/Ethiopia'
link2='http://en.wikipedia.org/wiki/Russia'
identification = { 'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}
requestToServer2 = urllib2.Request(link2,headers=identification)
responseFromServerInHTML2 = urllib2.urlopen(requestToServer2)
subSoup = BS(responseFromServerInHTML2,'lxml')
coords=subSoup.find_all("span",{'class': 'geo'})[0].string
print coords
有两个geo类,findall可以同时获得:
如果需要第二个元素,只需访问第二个元素:
您可以使用colspan查找第二个:
相关问题 更多 >
编程相关推荐