Python 爬取豆瓣电影数据

import json
from urllib import request

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36'
}

# 豆瓣电影url
url = "https://movie.douban.com/j/new_search_subjects?sort=T&range=0,10&tags=&start=0"

# 发送请求
req = request.Request(url, headers=headers)
response = request.urlopen(req)

content = response.read().decode()

# json解析
result = json.loads(content)

# 获取电影数据
movie = result['data']

for n in movie:
    title = n['title']  # 电影名称
    url = n['url']  # url

    # 文件存储
    with open('douban.txt', 'a', encoding='utf-8') as fp:
        s = f'{title},{url}\n'
        fp.write(s)

上一篇:word2vec 实现 影评情感分析


下一篇:python3.7爬取唐探3,李焕英豆瓣短评,来一波词云秀