From a957e8e557f7a3197c75b18fb05dce1a8c50cfa9 Mon Sep 17 00:00:00 2001 From: 2509165042 <2509165042@student.edu.cn> Date: Tue, 24 Mar 2026 11:22:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3.24作业.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 3.24作业.py diff --git a/3.24作业.py b/3.24作业.py new file mode 100644 index 0000000..2e009d3 --- /dev/null +++ b/3.24作业.py @@ -0,0 +1,18 @@ +import requests +from bs4 import BeautifulSoup +url='https://movie.douban.com/top250' +params={'start':0,'limit':25} +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' +} +response=requests.get(url,params=params,headers=headers) +html_content="" +if response.status_code==200: + html_content=response.text + soup=BeautifulSoup(html_content,'lxml') + movie_items=soup.select('div.item') + for item in movie_items: + movie_name=item.find('span',class_='title').text + print(movie_name) +else: + print(f"请求失败,状态码:{response.status_code}") \ No newline at end of file