Compare commits

..

3 Commits

Author SHA1 Message Date
81c1ceb86c 上传文件至 / 2026-03-26 16:09:25 +08:00
2509165036
c28f614355 完成作业X 2026-03-24 11:35:16 +08:00
2509165036
73cf5976cb 完成作业X 2026-03-24 11:22:10 +08:00
2 changed files with 48 additions and 0 deletions

27
2509165012+3.26.py Normal file
View File

@@ -0,0 +1,27 @@
import requests
from bs4 import BeautifulSoup
import time
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'}
for i in range(5):
try:
response = requests.get('https://picsum.photos/', headers=headers, timeout=10)
response.encoding = 'utf-8'
soup = BeautifulSoup(response.text, 'html.parser')
img_tag = soup.select_one('img.resize')
if not img_tag:
print(f"{i+1}张:未找到图片标签,跳过")
continue
img_src = img_tag['src']
img_response = requests.get(img_src, headers=headers, timeout=10)
filename = f'image_{i+1}.jpg'
with open(filename, 'wb') as f:
f.write(img_response.content)
print(f"{i+1}张:下载完成 → {filename}")
time.sleep(1)
except Exception as e:
print(f"{i+1}张:下载失败 → {e}")

21
2509165036胡红辉.py Normal file
View File

@@ -0,0 +1,21 @@
import requests
from bs4 import BeautifulSoup
headers ={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
}
url = 'https://www.douban.com/doulist/3936288/?start=0&sort=time&playable=0&sub_type='
response = requests.get(url, headers=headers, timeout=10)
response.encoding = 'utf-8'
soup = BeautifulSoup(response.text, 'html.parser')
movies = []
for a in soup.find_all('a'):
href = a.get('href', '')
if '/subject/' in href:
title = a.get_text(strip=True)
print(title)
movies.append(title)
print('-----------')
print(movies)
print(f"{page+1}页:{title}")
print(f"1 第{page+1}页爬取完成,共{len(movies)}条数据\n")
print(f"错第{page+1}页爬取失败:{e}")