源自:6-4 BeautifulSoup实例测试
使用idea运行时总是报错,Python是3.5的
代码如下:
from bs4 import BeautifulSoup
html_doc = """
The Dormouse's storyThe Dormouse's story
Once upon a time there were three little sisters; and their names were
Lacie and
and they lived at the bottom of a well.
...
"""
soup = BeautifulSoup(html_doc,'html_parser',from_encoding='utf-8')
print('获取所有链接')
links = soup.find_all('a')
for link in links :
print(link.name,link['href'],link.get_text())
提问者:慕仰0361636
2017-08-03 13:55