作业1
import requests import json for i in range(10): URL = 'https://api.ixiaowai.cn/api/api.php?return=json' resp = requests.get(url=URL) resp.encoding = 'utf-8-sig' data = json.loads(resp.text) print(data, type(data)) img_url = data['imgurl'] print(img_url) img_resp = requests.get(url=img_url) name = i with open(f'{name}.jpg','wb') as f1: f1.write(img_resp.content) 作业2
import requests from re import search, findall, finditer url = 'https://www.chinanews.com.cn/scroll-news/news1.html' headers = { 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36' } resp = requests.get(url=url,headers=headers) resp.encoding = 'UTF-8' title = findall(r'<div class="dd_lm">\[<a href=.