网盛资源- 最新刷机包,救砖解锁,刷机工具教程,免费下载,安卓免费APP下载,源码资源,破解软件资源,辅助游戏工具

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2870|回复: 0

[源码分享] 爬取网站排名前10电影信息

[复制链接]

1万

主题

6395

帖子

4万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
49067
发表于 2023-7-6 14:51:37 | 显示全部楼层 |阅读模式
  1. 爬取网站排名前10电影信息,代码如下:
  2. # -*- coding: utf-8 -*-

  3. import requests
  4. from pyquery import PyQuery as pq
  5. import re

  6. url = 'https://ssr1.scrape.center/'
  7. html = requests.get(url).text
  8. doc = pq(html)
  9. items = doc('.el-card').items()

  10. file = open('movie.txt','w',encoding='utf-8')
  11. for item in items:
  12.     item = pq(item)
  13.     # 电影名称
  14.     name = item.find('a > h2').text()
  15.     file.write(f'名称:{name}\n')
  16.     # 类别
  17.     categories = [cat.text() for cat in item.find('.categories button span').items()]
  18.     file.write(f'类别:{categories}\n')
  19.     # 上映时间
  20.     published_at = item.find('.info:contains(上映)').text()
  21.     published_at = re.search('(\d{4}-\d{2}-\d{2})',published_at). group(1) \
  22.     if published_at and re.search('\d{4}-\d{2}-\d{2}',published_at) else None
  23.     file.write(f'上映时间:{published_at}\n')
  24.     # 评分
  25.     score  = item.find('p.score').text()
  26.     file.write(f'评分:{score}\n')
  27.     file.write(f'{"=" * 50}\n')
  28. file.close()
复制代码


回复

使用道具 举报

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

本版积分规则

QQ|Archiver|小黑屋|网盛资源论坛 ( 粤ICP备2022085098号 )|网站地图

GMT+8, 2026-11-13 04:53 , Processed in 0.127739 second(s), 25 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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