作者iftrush (等一个人的回信,没错是你)
看板Python
标题[问题] 爬虫问题
时间Tue Jul 17 10:11:56 2018
小弟爬虫新手
目前正在爬字典(已成功用网页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://webptt.com/cn.aspx?n=bbs/Python/M.1531793524.A.411.html
1F:→ bibo9901: .select('meta[name="twitter:description"]')[0] 07/17 10:17
2F:→ iftrush: 有办法只产生" "里的东西吗? 07/17 10:28
3F:→ iftrush: 我自己是可以把meaning = str(meaning) 07/17 10:35
4F:→ iftrush: return meaning[15:-53] 07/17 10:36
5F:→ iftrush: 还是有其他方法可以用? 07/17 10:36
6F:→ TitanEric: 建议用with statement去抓urlopen 07/17 10:55
7F:推 coeric: findAll('meta', attrs={'name':'twitter:description'}) 07/17 10:57
8F:→ coeric: 我自己习惯用attrs # . 这之类的我比较记不住 07/17 11:00