import requests # 伪造浏览器发起http请求 from bs4 import BeautifulSoup ''' 将html格式的字符串解析成对象,通过对戏.find .find_all 查找 ''' response = requests.get( url="https://www.autohome.com.cn/news/", headers={ 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36' } ) # response = requests.get("https://dig.chouti.com/") response.encoding="gbk" soup = BeautifulSoup(response.text,'html.parser') content_list = soup.find(name='div',id='content-list')