找回密码
 立即注册
搜索
热搜: Excel discuz
查看: 1457|回复: 0

爬取电影论坛前十页分析存储电影类型到Excel

[复制链接]

482

主题

7万

元宝

75万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
750849
发表于 2021-5-21 15:36:55 | 显示全部楼层 |阅读模式
  1. import requests
  2. from pyquery import PyQuery
  3. from openpyxl import Workbook
  4. wb = Workbook()                                  #创建一个Excel文件
  5. sheet = wb.active
  6. sheet['a1'] = '类型'
  7. sheet['b1']= '个数'

  8. move = []                                      #存储电影全称
  9. cla = []                                        #存储电影类型

  10. tem = 'https://club.coovm.com/forum-53-{pn}.html'

  11. for page in range(1,11):

  12.     url = tem.format(pn=page)

  13.     spon = requests.get(url=url)
  14.     #print(spon.text)                    #获得HTML网页数据
  15.     #print(spon.content)                 #获得返回的数据(二进制)
  16.     doc = PyQuery(spon.text)

  17.     for item in doc.items('#threadlisttableid .xst'):

  18.         move.append([item.text()])

  19.         cla.append(item.text().split('】')[0]+'】')

  20. cls = []
  21. wordset = list(set(cla))
  22. for word in wordset:
  23.     freq = cla.count(word)
  24.     cls.append([word,freq])
  25.     sheet.append([word,freq])
  26. wb.save('电影类型1.xlsx')

复制代码

代码还能精简,整了几个小时有点头蒙,以后有机会再弄

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|五花八门论坛 ( 豫ICP备15031300号-3 )

GMT+8, 2024-4-26 12:26 , Processed in 0.135974 second(s), 26 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表