import re
import requests
url = 'https://maoyan.com/films'
headers = {
'Content-Type': 'text/plain; charset=UTF-8',
'Origin': 'https://maoyan.com',
'Referer': 'https://maoyan.com/board/4',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
}
resp = requests.get(url, headers=headers)
content = resp.text
# print(resp.text)
# resp.close()
re_1 = re.compile(r'<span class="name ">(?P<name>.*?)</span>', re.S)
result = re_1.finditer(content)
n = 0
for i in result:
n += 1
print(n, "电影名:",i.group('name'))
# print(i.group('type'))
resp.close()
|