代码:
import requests from bs4 import BeautifulSoup r=requests.get("http://exesoft.gitee.io/webshow/spider.html") r.encoding="utf-8" soup=BeautifulSoup(r.text,"html.parser") print(soup.title) print(soup.title.string) print(soup.p) print(soup.a) print(soup.a.attrs) print("-----------") myP=soup.find_all("p") for p in myP: print(p.string) print("-----------") myA=soup.find_all("a") for a in myA: print(a.string)
课后作业:
1.复制上述代码,在Python环境下运行。
2.读懂上述代码。