day17-正则表达式作业2

import requests
from re import findall


def get_url():
    url = 'https://movie.douban.com/top250?start=0&filter='
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36'
    }
    response = requests.get(url, headers=headers)
    result = response.text
    return result


def massage():
    url_str = get_url()
    # 电影名字
    name = findall(r'(\w*)', url_str)
    # 电影相关信息
    relate = findall(r'(\d*) / ([\w\s]*) / ([\w\s]*)\n\s*', url_str)
    # 电影评分
    score = findall(r'([\d.]*)', url_str)
    # 电影评价人数
    assessment = findall(r'(\d+\w*)', url_str)
    # 电影介绍
    introduce = findall(r'(.*)', url_str)

    movie = [[name[x], relate[x][0], relate[x][1], relate[x][2], score[x], assessment[x], introduce[x]] for x in range(25)]
    return movie


print(massage())

你可能感兴趣的:(学习,python)