资源简介
用Python爬虫从豆瓣电影的首页那一页中,爬取那页的电影名称,上映时间,国家,豆瓣评分,主演,然后再讲结果写到*.txt文件中
代码片段和文件信息
# _*_ encoding:utf-8 _*_
import requests
from bs4 import BeautifulSoup
import json
import time
import random
def get_movie_id(types):
ids = []
contents = requests.get(
‘https://movie.douban.com/j/search_subjects?type=movie&tag={0}&sort=recommend&page_limit=50&page_start=0‘.format(
types))
subjiects = json.loads(contents.content.decode(“utf-8“))[“subjects“]
for subject in subjiects:
ids.append(subject[‘id‘])
print(ids)
return ids
def detail(_id):
content = requests.get(‘https://movie.douban.com/j/subject_abstract?subject_id={0}‘.format(_id))
subject = json.loads(content.content.decode(“u
评论
共有 条评论