[問題] 爬蟲問題

作者: iftrush (綾絹姊)   2018-07-17 10:11:56
小弟爬蟲新手
目前正在爬字典(已成功用網頁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'
作者: TitanEric (泰坦)   2018-07-17 10:55:00
建議用with statement去抓urlopen
作者: iftrush (綾絹姊)   2018-07-17 10:28:00
有辦法只產生" "裡的東西嗎?我自己是可以把meaning = str(meaning)return meaning[15:-53]還是有其他方法可以用?
作者: bibo9901 (function(){})()   2018-07-17 10:17:00
.select('meta[name="twitter:description"]')[0]
作者: coeric ( )   2018-07-17 10:57:00
findAll('meta', attrs={'name':'twitter:description'})我自己習慣用attrs # . 這之類的我比較記不住

Links booklink

Contact Us: admin [ a t ] ucptt.com