爬取豆瓣网电影的数据信息
# -*- coding: utf-8 -*-
import requests
import json
from bs4 import BeautifulSoup
def get_page():
# 1. url
url= 'https://movie.douban.com/cinema/nowplaying/kaifeng/'
# 2. 请求时应该发送什么数据
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36',
}
# 3. GET/POST请求
#采用GET
#4. 发送数据
response = requests.get(url,headers=headers)
return response.text
def parse_page(text):
movies = []
soup = BeautifulSoup(text,'lxml')
liList = soup.find_all('li',attrs={"data-category":"nowplaying"})
for li in liList:
movie = {}
title = li['data-title']
score = li['data-score']
release = li['data-release']
duration = li['data-duration']