From e75d7317c35773e34ee6ae1c093ed777833abed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=A6=A4=E7=8F=8A?= <2509165025@student.example.com> Date: Mon, 6 Jul 2026 13:12:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E7=88=AC=E8=99=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 爬虫 | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 爬虫 diff --git a/爬虫 b/爬虫 new file mode 100644 index 0000000..c12258f --- /dev/null +++ b/爬虫 @@ -0,0 +1,41 @@ +import re +import requests +from bs4 import BeautifulSoup as bs +import json + +header = {'User-Agent': 'Mozilla/5.0'} +url = 'https://exam.detr.top/exam-b/movies' + +html = requests.get(url, headers=header).text + +open('movies.html', 'w', encoding='utf-8').write(html) +print(html) +print('----------------') + +fd = re.search(r'exam_fingerprint:\s*(\S+)', html).group(1) +print(fd) + +resp = bs(html, 'html.parser').find_all('tr', class_='item-row') +movies = [] + +for i in resp: + c = [] + for r in i.find_all('td'): + c.append(r.text.strip()) + movies.append({ + 'id': int(c[0]), + 'title': c[1], + 'director': c[2], + 'year': int(c[3]), + 'rating': float(c[4]), + 'duration': int(c[5]), + 'genre': c[6], + 'actors_count': int(c[7]) + }) + +json.dump( + {'ID': fd, 'movies': movies}, + open('movies.json', 'w', encoding='utf-8'), + ensure_ascii=False, + indent=2 +) \ No newline at end of file