浅用chatgpt

image

import requests
from bs4 import BeautifulSoup

# 设置请求头,模拟浏览器访问
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}

# 设置要爬取的页面数量
page_num = 5

# 循环爬取每一页的数据
for i in range(page_num):
    url = 'https://movie.douban.com/top250?start=' + str(i * 25) + '&filter='
    response = requests.get(url, headers=headers)
    soup = BeautifulSoup(response.text, 'html.parser')
    movie_list = soup.find_all('div', class_='info')

    # 循环解析每一部电影的信息
    for movie in movie_list:
        title = movie.find('span', class_='title').text
        rating = movie.find('span', class_='rating_num').text
        if float(rating) >= 9.5:
            print(title + ' ' + rating)

image


image
image
image

posted @ 2023-03-27 22:40  yub4by  阅读(61)  评论(0编辑  收藏  举报