爬虫学习,豆瓣电影排行


import requests


url = 'https://movie.douban.com/typerank?type_name=%E5%8A%A8%E4%BD%9C&type=5&interval_id=100:90&action='
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'
    }


response = requests.get(url=url, headers=headers)
response.encoding = response.apparent_encoding
page_text = response.text

with open('./douban.html', 'w', encoding='utf-8') as fp:
    fp.write(page_text)


print("完成")


import requests



url = 'https://movie.douban.com/j/chart/top_list'

params = {
    'type': '5',
    'interval_id': '100:90',
    'action': '',
    'start': '10',
    'limit': '60',
    }

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'
    }

response = requests.get(url=url, params=params, headers=headers)
response.encoding = response.apparent_encoding
page_text = response.json()


for movie in page_text:
    name = movie['title']
    score = movie['score']
    print(name, score)

   

你可能感兴趣的:(笔记)