Compare commits
3 Commits
374b06bb6e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 81c1ceb86c | |||
|
|
c28f614355 | ||
|
|
73cf5976cb |
27
2509165012+3.26.py
Normal file
27
2509165012+3.26.py
Normal 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
21
2509165036胡红辉.py
Normal 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}")
|
||||
Reference in New Issue
Block a user