diff --git a/26wyc.py b/26wyc.py new file mode 100644 index 0000000..b74a76b --- /dev/null +++ b/26wyc.py @@ -0,0 +1,18 @@ +import requests +import re +url = 'https://movie.douban.com/top250' +headers = { + 'User-Agent':'Mozilla/5.0(Windows NT 6.1: Win64; x64)AppleWebkit/537.36(KHTML,like Gecko) Chrome/120.0.0.0 Safari/537.36' +} + +response = requests.get(url,headers=headers) +response.encoding = 'utf-8' +html = response.text +pattern = r'(.*?)' +titles = re.findall(pattern,html) +chinese_titles = [titles for title in titles if "/" not in title ] +top10_titles = chinese_titles[:10] +with open ("movies.txt","w",encoding="utf-8") as f: + for idx, titles in enumerate(top10_titles, 1): + f.write(f"{idx}.{titles}\n") + print("movies.txt已保存") \ No newline at end of file