加入收藏 | 设为首页 | 会员中心 | 我要投稿 西安站长网 (https://www.029zz.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

【Python爬虫+数据分析】2018年电影,你看了几部?

发布时间:2018-12-23 07:47:19 所属栏目:教程 来源:法纳斯特
导读:副标题#e# 12月已开始了,离2018年的结束也就半个多月的时间了,还记得年初立下的flag吗? 完成了多少?相信很多人和我一样,抱头痛哭... 本次利用猫眼电影,实现对2018年的电影大数据进行分析。 一、网页分析 01 标签 通过点击猫眼电影已经归类好的标签,得

02 获取电影详情页链接

  1. def get_url(): 
  2.     """ 
  3.     获取电影详情页链接 
  4.     """ 
  5.     for i in range(0, 300, 30): 
  6.         time.sleep(10) 
  7.         url = 'http://maoyan.com/films?showType=3&yearId=13&sortId=3&offset=' + str(i) 
  8.         host = """Referer:http://maoyan.com/films?showType=3&yearId=13&sortId=3&offset=0 
  9.         """ 
  10.         header = head + host 
  11.         headers = str_to_dict(header) 
  12.         response = requests.get(url=url, headers=headers) 
  13.         html = response.text 
  14.         soup = BeautifulSoup(html, 'html.parser') 
  15.         data_1 = soup.find_all('div', {'class': 'channel-detail movie-item-title'}) 
  16.         data_2 = soup.find_all('div', {'class': 'channel-detail channel-detail-orange'}) 
  17.         num = 0 
  18.         for item in data_1: 
  19.             num += 1 
  20.             time.sleep(10) 
  21.             url_1 = item.select('a')[0]['href'] 
  22.             if data_2[num-1].get_text() != '暂无评分': 
  23.                 url = 'http://maoyan.com' + url_1 
  24.                 for message in get_message(url): 
  25.                     print(message) 
  26.                     to_mysql(message) 
  27.                 print(url) 
  28.                 print('---------------^^^Film_Message^^^-----------------') 
  29.             else: 
  30.                 print('The Work Is Done') 
  31.                 break 

(编辑:西安站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读