#爬取卖菜网最新消息
from bs4 import BeautifulSoup
import requests
url = "http://www.maicainan.com/"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 Edg/95.0.1020.40"
}
res = requests.get(url, headers=headers)
page = BeautifulSoup(res.text, "html.parser")
div = page.find("div", class_="im_list")
li = div.find_all("li")
for a in li:
data = a.find_all("a")
title = data[0].text
print(title)
res.close()