作者iftrush (等一个人的回信,没错是你)
看板Python
标题[问题] 爬虫,find()找重复的标签
时间Wed Jul 18 05:44:19 2018
小弟爬虫新手
正在用google的geocode做爬虫练习
以下是部分原始码
<GeocodeResponse>
<status>OK</status>
<result>
<type>establishment</type>
<type>point_of_interest</type>
<type>university</type>
已知用bsobj.find("result").find("type")是第一个type
请问要如何用find或是next_sibling去爬第二个和第三个type?
ps:试过用next_sibling()
dataType = bsobj.find("result").find("type")
dataType2 = dataType.next_sibling()
return dataType2
系统给我
TypeError: 'NavigableString' object is not callable
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 73.223.41.252
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1531863864.A.D8C.html
1F:推 weel99699: 你可以试试看用findall看看 07/18 05:47
2F:→ iftrush: 恩,可以findAll("type")[1]可弄出第二个 07/18 05:51
3F:→ iftrush: 不过next_sibling的问题要如何解决? 07/18 05:52
4F:推 chen1i6c04: for回圈 + findall("type") 07/18 07:41
5F:推 TitanEric: next_sibling不是method 不用()另外也可以从错误讯息 07/18 10:33
6F:→ TitanEric: 看出来 07/18 10:33