吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2077|回复: 36
收起左侧

[学习记录] 爬取网站排名前10电影信息

[复制链接]
大白baymax 发表于 2023-6-24 17:35
爬取网站排名前10电影信息,代码如下:
[Python] 纯文本查看 复制代码
# -*- coding: utf-8 -*-

import requests
from pyquery import PyQuery as pq
import re

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

file = open('movie.txt','w',encoding='utf-8')
for item in items:
    item = pq(item)
    # 电影名称
    name = item.find('a > h2').text()
    file.write(f'名称:{name}\n')
    # 类别
    categories = [cat.text() for cat in item.find('.categories button span').items()]
    file.write(f'类别:{categories}\n')
    # 上映时间
    published_at = item.find('.info:contains(上映)').text()
    published_at = re.search('(\d{4}-\d{2}-\d{2})',published_at). group(1) \
    if published_at and re.search('\d{4}-\d{2}-\d{2}',published_at) else None
    file.write(f'上映时间:{published_at}\n')
    # 评分
    score  = item.find('p.score').text()
    file.write(f'评分:{score}\n')
    file.write(f'{"=" * 50}\n')
file.close()


欢迎各位大佬们批评指正。

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

alsyat 发表于 2023-6-24 18:48
貌似坐了沙发。
yy103050 发表于 2023-6-24 19:02
yoyoma211 发表于 2023-6-24 19:03
jiahang 发表于 2023-6-24 19:50
学到了感谢作者
头像被屏蔽
moruye 发表于 2023-6-24 20:52
提示: 作者被禁止或删除 内容自动屏蔽
cccwww 发表于 2023-6-24 21:00
感谢大佬分享
muyan888 发表于 2023-6-24 22:06
感谢分享
orb001 发表于 2023-6-24 23:29
谢谢分享
lancou 发表于 2023-6-24 23:53
过来学习学习,感谢分享
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-6-5 16:05

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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