编程语言
首页 > 编程语言> > Python 简单爬虫

Python 简单爬虫

作者:互联网

from bs4 import BeautifulSoup
import requests

if name==“main”:
target=“https://mbd.baidu.com/newspage/data/landingsuper?context=%7B%22nid%22%3A%22news_9433710732874198416%22%7D&n_type=0&p_from=1”
bf=BeautifulSoup(requests.get(target).text)
textes=bf.find_all(‘span’,class_=“bjh-p”)

print(textes[0].text.replace('\xa0' * 8, '\n\n'))
print(textes[1].text.replace('\xa0' * 8, '\n\n'))
print(textes[2].text.replace('\xa0' * 8, '\n\n'))

标签:Python,text,爬虫,replace,xa0,textes,BeautifulSoup,简单,print
来源: https://blog.csdn.net/qq_42212829/article/details/120272680