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

看板Python作者 (等一個人的回信,沒錯是你)時間7年前 (2018/07/18 05:44), 編輯推噓3(303)
留言6則, 4人參與, 7年前最新討論串1/1
小弟爬蟲新手 正在用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://www.ptt.cc/bbs/Python/M.1531863864.A.D8C.html

07/18 05:47, 7年前 , 1F
你可以試試看用findall看看
07/18 05:47, 1F

07/18 05:51, 7年前 , 2F
恩,可以findAll("type")[1]可弄出第二個
07/18 05:51, 2F

07/18 05:52, 7年前 , 3F
不過next_sibling的問題要如何解決?
07/18 05:52, 3F

07/18 07:41, 7年前 , 4F
for迴圈 + findall("type")
07/18 07:41, 4F

07/18 10:33, 7年前 , 5F
next_sibling不是method 不用()另外也可以從錯誤訊息
07/18 10:33, 5F

07/18 10:33, 7年前 , 6F
看出來
07/18 10:33, 6F
文章代碼(AID): #1RJcCusC (Python)
文章代碼(AID): #1RJcCusC (Python)