1 #-*- coding:utf-8 -*- 2 __author__ = "MuT6 Sch01aR" 3 4 import requests 5 from bs4 import BeautifulSoup 6 7 response = requests.get( 8 url='http://www.djhaiba.com/dance/list-id-1-1.html' 9 ) 10 response.encoding = response.apparent_encoding #设置编码 11 12 soup = BeautifulSoup(response.text,features='html.parser') 13 14 target = soup.find(id="p1") 15 16 li_list = target.find_all("li") #生成的为一个列表 17 18 for i in li_list: 19 p = i.find('p') 20 a = p.find('a') 21 print(a.text) #打印a标签的文本内容 22 print(a.attrs.get('href'))