python beautifulsoup获取html标记内容

python beautifulsoup获取html标记内容,python,beautifulsoup,Python,Beautifulsoup,如何使用beautifulsoup获取html标记的内容?例如标签的内容 我试过: from bs4 import BeautifulSoup url ='http://www.websiteaddress.com' soup = BeautifulSoup(url) result = soup.findAll('title') for each in result: print(each.get_text()) 但什么也没发生。我在用蟒蛇3 您需要先获取网站数据。您可以使用urll

如何使用beautifulsoup获取html标记的内容?例如
标签的内容

我试过:

from bs4 import BeautifulSoup

url ='http://www.websiteaddress.com'
soup = BeautifulSoup(url)
result = soup.findAll('title')
for each in result:
    print(each.get_text())

但什么也没发生。我在用蟒蛇3

您需要先获取网站数据。您可以使用
urllib.request
模块来实现这一点。请注意,HTML文档只有一个标题,因此不需要使用
find_all()
和循环

from urllib.request import urlopen
from bs4 import BeautifulSoup

url ='http://www.websiteaddress.com'
data = urlopen(url)
soup = BeautifulSoup(data, 'html.parser')
result = soup.find('title')
print(result.get_text())

@我很高兴能帮上忙!