新操作
import requests from bs4 import BeautifulSoup url="http://news.gzcc.cn/html/xiaoyuanxinwen/" res=requests.get(url) res.encoding="utf-8" soup=BeautifulSoup(res.text,'html.parser') # for news in soup.select('li'): # if len(news.select('.news-list-title')) >0: # print(news.select('.news-list-title')) for newc in soup.select('li'): if len(newc.select('.news-list-title'))>0: d=newc.select('a')[0].attrs['href'] res1=requests.get(d) res1.encoding="utf-8" e=BeautifulSoup(res1.text,'html.parser') content=e.select('#content')[0].text show=e.select('.show-info')[0].text print(content,show)