import requests newsurl='http://news.gzcc.cn/html/2018/xiaoyuanxinwen_0327/9106.html' res =requests.get(newsurl) res.encoding='utf-8'
取出h1标签的文本
print(soup.h1.text)
取出a标签的链接
print(soup.a.attrs['href'])
取出所有li标签的所有内容
for i in soup.select('li'): print(i.contents)
取出一条新闻的标题、链接、发布时间、来源
print(soup.select('.news-list-title')[0].text) print(soup.select('li')[2].a.attrs['href']) print(soup.select('.news-list-info')[0].contents[0].text) print(soup.select('.news-list-info')[0].contents[1].text)