【发布时间】:2016-12-27 12:53:24
【问题描述】:
我正在尝试从内容中获取文本,但是当我在结果变量上尝试漂亮的汤函数时,它会导致错误。
from bs4 import BeautifulSoup as bs
import requests
webpage = 'http://www.dictionary.com/browse/coypu'
r = requests.get(webpage)
page_text = r.text
soup = bs(page_text, 'html.parser')
result = soup.find_all('meta', attrs={'name':'description'})
print (result.get['contents'])
我正在尝试读取结果;
“海狸鼠的定义,一种大型的南美水生啮齿动物,Myocastor(或 Myopotamus)海狸鼠,产生毛皮海狸鼠。查看更多信息。”
【问题讨论】:
-
result.get('contents')也许? -
你在result.get中有问题,应该使用result[0].get("content"),你正在使用“contents”。
标签: python regex beautifulsoup