作者dynastat (dynastat)
看板Python
标题[问题] bs4 findAll method 後如何提取content?
时间Sun Feb 5 14:39:19 2017
大家好
我在练习用爬虫爬yahoo字典的资料
原始码如下:
import requests
from bs4 import BeautifulSoup
Url = requests.get('
http://tw.dictionary.search.yahoo.com/search?p=fat')
TargetHtml = BeautifulSoup(Url.text,"html.parser")
parser = TargetHtml.findAll('span', class_='fc-6th fz-15px')
print (parser.contents)
却会出现
AttributeError: 'ResultSet' object has no attribute 'contents'
可是我看Stackoverflow 都是这样提取内文的啊?
要如何正确提取内文呢?
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 118.163.12.74
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1486276763.A.6D0.html
1F:推 crazycy: parser[0].text # 'a.形容词' 02/05 15:43
2F:→ crazycy: parser[1].text # 'n.名词' 02/05 15:44
3F:→ crazycy: parser[2].text # 'vi.不及物动词' 02/05 15:44
4F:推 crazycy: parser可以视作包含Tag的list 02/05 15:47
5F:→ crazycy: 从Tag取text就是那个节点的文字内容了 02/05 15:48