huangjiaxiaoluobo

python爬虫-爬取豆瓣电影数据

#!/usr/bin/python
# coding=utf-8
# 作者 :Y0010026
# 创建时间 :2018/12/16 16:27
# 文件 :spider_05.py
# IDE :PyCharm

import urllib2
import urllib

url = \'https://movie.douban.com/j/new_search_subjects?sort=T&range=0,10\'

# 要传递的post方式的数据,有可能会有多组数据
submit_data = {
\'start\': 20,
\'tags\': \'喜剧\'
}

# 编码
data = urllib.urlencode(submit_data)

# 构造请求头,创建请求对象
headers = {
"Accept": "application/json,text/plain,*/*",
"User-Agent": "Mozilla/5.0(WindowsNT6.1;rv:2.0.1)Gecko/20100101Firefox/4.0.1",
"Accept-Language": "zh-CN,zh;q=0.8"
}
requset = urllib2.Request(url, data=data, headers=headers)

# 发送请求,获取服务器响应数据
response = urllib2.urlopen(requset)

# 获取爬取到的数据
content = response.read()

# 保存数据
with open(\'movies.json\', \'w\') as f:
f.write(content)

分类:

技术点:

相关文章:

  • 2021-11-24
  • 2021-10-15
  • 2021-10-15
  • 2021-09-01
  • 2021-10-13
  • 2021-10-07
  • 2021-10-15
猜你喜欢
  • 2021-10-05
  • 2021-06-25
  • 2021-10-15
  • 2022-01-01
  • 2021-10-03
  • 2021-10-08
相关资源
相似解决方案