[問題] 爬蟲,find()找重複的標籤

作者: iftrush (綾絹姊)   2018-07-18 05:44:19
小弟爬蟲新手
正在用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
作者: weel99699 (旦旦)   2018-07-18 05:47:00
你可以試試看用findall看看
作者: iftrush (綾絹姊)   2018-07-18 05:51:00
恩,可以findAll("type")[1]可弄出第二個不過next_sibling的問題要如何解決?
作者: chen1i6c04 (輕踏水無痕)   2018-07-18 07:41:00
for迴圈 + findall("type")
作者: TitanEric (泰坦)   2018-07-18 10:33:00
next_sibling不是method 不用()另外也可以從錯誤訊息看出來

Links booklink

Contact Us: admin [ a t ] ucptt.com