chentianxiang180
#!/usr/bin/env python
#!--*--coding:utf-8 --*--
#!@Time    :2018/7/8 19:50
#!@Author   TrueNewBee\
#爬取我不是药神猫眼电影影评
#2018-7-8 19:29:54
#一个不是很成功的   大致意思是还是学的不通  因为思路就是和爬电影思路一样
#但是  bs4  BeautifulSop库都没学明白!别觉得学个爬虫自以为是!小儿科东西!
#好好学有用的基础

import requests
from bs4 import BeautifulSoup
import json

#1.获取页面
#2.获取影评

def  main():
    """获取页面源码"""
    url = "http://maoyan.com/films/1200486"
    headers={
    \'User-Agent\': \'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36\',
    \'Host\': \'maoyan.com\'
    }
    request = requests.get(url,headers=headers).text
       #创建对象  解析网页
    r = BeautifulSoup(request,"html.parser")
    result = r.find_all("div",{\'class\':\'comment-content\'})
    """"把提取的数据写入文件"""
    with open("我不是药神部分影评价.txt", "a", encoding="utf-8") as f:
        print(type(json.dumps(result)))
        f.write(json.dumps(result, ensure_ascii=False) + \'\n\')  # 使用json模块实现字典的序列化

if __name__ == \'__main__\':
    main()

 

分类:

技术点:

相关文章:

  • 2021-10-01
  • 2021-07-19
  • 2022-01-14
  • 2021-09-01
  • 2021-08-03
  • 2021-10-16
  • 2022-01-03
  • 2021-11-03
猜你喜欢
  • 2021-11-13
  • 2021-11-13
  • 2022-01-01
  • 2021-09-01
  • 2021-10-03
  • 2021-10-05
  • 2021-04-05
相关资源
相似解决方案