import requests
res= requests.get('https://news.sina.com.cn/china/')
res.encoding='utf-8'
#print(res.text)
效果图
图片.png
取出文字
from bs4 import BeautifulSoup
html_sample=' \
<html> \
<body> \
<h1 id="title"> hello world </h1 >\
<a href="#" class="link">这是一句话</a> \
<a href="#" class="link2">这是第二句句话</a> \
</body>\
</html>'
soup = BeautifulSoup(html_sample,'html.parser')
print(type(soup))
print(soup.text)
图片.png
拾取元素
1
图片.png
2
图片.png
3
图片.png
4
图片.png
5
图片.png
6
图片.png
7
图片.png
8
图片.png













网友评论