BeautifulSoup使用大致流程

使用BeautifulSoup流程

from bs4 import BeautifulSoup
import time
import requests
url='https://blog.csdn.net/Xiang_lhh/article/details/104940609'
resp=requests.get(url).text
result=BeautifulSoup(resp,'lxml')#将返回的对象解析
re=result.find('div',attrs={'class':'article_content'})#解析后,将html页面查找,find_all()表示将页面中所有符合条件的div标签返回
r=re.find_all('p')#表示将所有p标签的内容返回
print(r)
time.sleep(5)

此时,将目标url的首个符合条件的div中的p标签中的数据输出

猜你喜欢

转载自blog.csdn.net/Xiang_lhh/article/details/105345119