[問題] 爬蟲問題

看板Python作者 (等一個人的回信,沒錯是你)時間7年前 (2018/07/17 10:12), 編輯推噓1(107)
留言8則, 4人參與, 7年前最新討論串4/5 (看更多)
小弟爬蟲新手 目前正在爬字典(已成功用網頁API爬出意思) 假如我想爬apple(不使用API) 從page source裡知道意思在下面程式碼的content裡 <meta name="twitter:description" content=" "/> 我要如何用findall 或是 find 找到這句 然後print出content的" "裡的意思? 自己寫的程式碼 from urllib.request import urlopen from bs4 import BeautifulSoup def DictRequest(word): html = urlopen("https://www.merriam-webster.com/dictionary/"+ word) bsobj = BeautifulSoup(html.read(), 'html') meaning = bsobj.findAll('meta', name = 'twitter:description') TypeError: find_all() got multiple values for argument 'name' -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 73.223.41.252 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1531793524.A.411.html

07/17 10:17, 7年前 , 1F
.select('meta[name="twitter:description"]')[0]
07/17 10:17, 1F

07/17 10:28, 7年前 , 2F
有辦法只產生" "裡的東西嗎?
07/17 10:28, 2F

07/17 10:35, 7年前 , 3F
我自己是可以把meaning = str(meaning)
07/17 10:35, 3F

07/17 10:36, 7年前 , 4F
return meaning[15:-53]
07/17 10:36, 4F

07/17 10:36, 7年前 , 5F
還是有其他方法可以用?
07/17 10:36, 5F

07/17 10:55, 7年前 , 6F
建議用with statement去抓urlopen
07/17 10:55, 6F

07/17 10:57, 7年前 , 7F
findAll('meta', attrs={'name':'twitter:description'})
07/17 10:57, 7F

07/17 11:00, 7年前 , 8F
我自己習慣用attrs # . 這之類的我比較記不住
07/17 11:00, 8F
文章代碼(AID): #1RJL1qGH (Python)
討論串 (同標題文章)
文章代碼(AID): #1RJL1qGH (Python)