首页 > 编程语言 >python爬虫电影数据抓取实战

python爬虫电影数据抓取实战

时间:2023-01-16 10:36:16浏览次数:46  
标签:__ 抓取 python self 爬虫 urllib st timeout

想要了解最近电影院播放的都有什么影视电影,哪部值得推荐,如果单纯靠手动收搜不全面,下面我们就先使用urllib.request模块抓取整个网页,再使用re模块获取电影信息,做个简单的爬虫做个数据分析。

编写simpleCrawlerNowMoive.py代码如下

#!/usr/bin/env python
# coding: utf-8
__author__ = 'www.py3study.com'
import re
import urllib.request
class TodayMoive(object):
def __init__(self):
self.url = 'https://movie.douban.com/people/1166776/'
self.timeout = 3
self.filename = 'todaymoive.txt'
'''内部变量定义完毕'''
self.getmoiveinfo()

def getmoiveinfo(self):
response = urllib.request.urlopen(self.url, timeout=self.timeout)
content = response.read().decode('utf-8')
#findall匹配电影名字的段落
moivelist = re.findall('class="cover"><img alt="', '')
st = st.replace('"', '')
#split字符串切割,以' '空格为分隔符,取第0个值
st = st.split(' ')[0]
return st

if __name__ == '__main__':
tm = TodayMoive()

应该看到的结果

python爬虫电影数据抓取实战_网页爬虫

会在当前目录下生成一个todaymoive.txt文件,内容如下。

python爬虫电影数据抓取实战_python_02

如果单从这些代码看起来是不是以为不是爬虫,其实严格意义上来说这个就是爬虫,只是相对来说内容简单,爬取的数据相对较少。大体上的爬虫框架是这么回事,如果用来爬取大型项目也是没有问题的。

标签:__,抓取,python,self,爬虫,urllib,st,timeout
From: https://blog.51cto.com/u_13488918/6010090

相关文章

  • 【Python学习】图片放缩
    使用图片对模型进行训练时,对图片的大小有一定的要求,因此需要对图片进行放缩。安装包PILpipinstallPillow简单介绍基本使用方法#ImportsPILmodulefromPILi......
  • 学习python 爬虫之pyppteer
    1、安装pyppteer库 pipinstallpyppteer 如果安装出错,使用国内镜像安装 pipinstallpyppeteer-ihttps://pypi.douban.com/simple2、下载chromium浏览......
  • Python 量化交易编程技巧积累
    1.计算股票中的16个常用指标-stockstatus。地址:https://blog.csdn.net/freewebsys/article/details/785785482.获得全世界所有市场的交易日历-exchange_calendar。地址:ht......
  • 尝试python 爬虫新工具playwright
    1、安装playwright库pipinstallplaywright 2、安装浏览器驱动文件(安装过程稍微有点慢)python-mplaywrightinstall......
  • 【801】Python绘制机器学习特征相关性热力图
    参考:python特征相关性热力图怎么画_如何在python中绘制热地图(实例)参考:seaborn.heatmap参考:Choosingcolorpalettes根据具体的特征数据集,计算不同特征之间的相关性,然后......
  • AirSim 自动驾驶仿真 (2-3) python控制无人机 win10
    1首先搭建好环境参考 2python控制https://blog.csdn.net/Zhaoxi_Li/article/details/108002544官方代码位置 自己pythonj教程https://www.cnblogs.com/gooutlo......
  • python django学生选课系统
    pythondjango学生选课系统后端:Pythondjango数据库:MySQL前端:htmlcssjs实现功能:登录、注册、查看自己信息、修改自己信息等学生:看课、选课、查学分老师:创建课程、......
  • python利用subprocess执行shell命令
    subprocess以及常用的封装函数运行python的时候,我们都是在创建并运行一个进程。像Linux进程那样,一个进程可以fork一个子进程,并让这个子进程exec另外一个程序。在Python中,......
  • Python django 公寓管理系统
    Pythondjango公寓管理系统django公寓租房系统django酒店订购系统django公寓订购系统技术:Pythondjango数据库:MySQL前端:htmlcssjs涉及到的功能:登录、注册、......
  • Python django 会议室管理系统
    Pythondjango会议室管理系统django会议室申请系统django会议室系统技术:Pythondjango数据库:MySQL涉及功能:登录、注册、登出、管理员登录、管理用户信息等添加会......