学弟给的
import re
import requests
url = "https://movie.douban.com/top250"
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.42'
}
response = requests.get(url,headers=headers)
print(response.text)
results = response.text
reg = '<div class="item">.*?<span class="title">(.*?)</span>.*?'
movie_results = re.finditer(reg, results , re.S)
f = open("movies.tet",'w',encoding="utf-8")
for match in movie_results:
print(match.group(1))
f.writelines([match.group(1),"\n"])
f.close()
标签:python,movie,results,re,pycharm,top250,response,match
From: https://www.cnblogs.com/Vivian-0918/p/16989894.html