代码如下面所示:
#
实现豆瓣电影
top250
名单
[color=]import
requests
[color=]import
re
[color=]for
i
[color=]in
[color=]range
(
[color=]1
[color=],
[color=]11
):
page = (i -
[color=]1
) * 25
[color=]
url =
[color=]f"https://movie.douban.com/top250?start=
[color=]{
page
[color=]}
&filter="
[color=]
head = {
[color=]"User-Agent"
: "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/122.0.6261.95 Safari/537.36 "
[color=]
}
resp = requests.get(url
[color=],
[color=]headers
=head)
resp.encoding = "utf-8"
[color=]
obj = re.compile(r'.*?(?P.*?)'
r'.*?
(?P.*?) .*?'
r'(?P.*?).*?(?P.*?)
[color=]人评价
'
[color=],
re.S)
result = obj.finditer(resp.text)
[color=]for
item
[color=]in
result:
dic = item.groupdict()
dic[
[color=]'year'
] = dic[
[color=]'year'
].strip()
[color=]print
(dic)