From df8ebcb698a29243f70d71b09564010e5da32692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E9=9B=85=E9=9B=AF?= <2509165021@student.example.com> Date: Thu, 11 Jun 2026 21:27:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 爬豆瓣 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 爬豆瓣 diff --git a/爬豆瓣 b/爬豆瓣 new file mode 100644 index 0000000..8a33e64 --- /dev/null +++ b/爬豆瓣 @@ -0,0 +1,33 @@ +import requests +from bs4 import BeautifulSoup as bs +import json +headers = {'User-Agent':'Mozilla/5.0(Windows NT 10.0;Win64; x64) AppleWebKit/537.36(KHTML,like Gecko) Chrome/91.0.4472.124 Safari/537.36'} +url="https://movie.douban.com/top250?start=25" +data=[] +resp = requests.get(url, headers = headers) +resp.encoding='uft-8' +soup= bs(resp.text,"html.parser") +items= soup.find_all("div",class_="item") +#print(items[0]) +for i in range(len(items)): + print(i) + title=items[i].find("span",class_="title").get_text() + + actors=items[i].find("div",class_="bd").get_text().strip() + try: + actors=actors.split("主演:")[1].split("\n")[0] + except: + actors="无" + try: + quote=items[i].find("div", class_="bd").find("p",class_="quote").get_text().strip() + except: + quote="无" + data.append({ + "title":title, + "actor":actors, + "quote":quote + }) +print(data) + +with open("movie.json","w",encoding="utf-8") as f: + json.dump(data,f,ensure_ascii=False,indent=4)