python爬取电影网站信息并写入文件
1 #https://www.domp4.com/list/6-1.html 2 import requests 3 import re 4 from bs4 import BeautifulSoup 5 from urllib.parse import urlparse,parse_qs 6 import os 7 8 9 def get_url_content(url): //获取网站的源码 10 response=requests.get(url) 11 if response.status_code==200: 12 return response.text 13 else: 14 return False 15 16 def parse_Web_Content(content): 17 Object=BeautifulSoup(content,'html.parser') 18 19 filmName=get_film_name(Object) 20 filmCast=get_film_cast(Object) 21 filmIntro=get_film_introduction(Object) 22 filmUrl=get_film_url(Object) 23 24 film=[] 25 for i in range(len(filmName)): 26 indiv={ 27 'fileName':filmName[i], 28 'filmCast':filmCast[i], 29 'filmIntro':filmIntro[i], 30 'filmurl':'https://www.domp4.com'+filmUrl[i] 31 } 32 film.append(indiv) 33 return film 34 35 36 def get_film_name(Soup): 37 Name=Soup.select(".play_info") 38 name_list=[] 39 for i in range(len(Name)): 40 parsedName=Name[i].a.string 41 name_list.append(parsedName) 42 return name_list 43 44 def get_film_cast(Soup): 45 Cast=Soup.find_all('p',attrs={'class':'space'}) 46 film_Cast = [] 47 for i in range(len(Cast)): 48 parsedCast=Cast[i].text 49 film_Cast.append(parsedCast) 50 return film_Cast 51 52 def get_film_introduction(Soup): 53 Introduction=Soup.find_all('p',attrs={'class':'content'}) 54 intro_list=[] 55 for i in range(len(Introduction)): 56 parsedIntro=Introduction[i].text 57 intro_list.append(parsedIntro) 58 return intro_list 59 60 def get_film_url(Soup): 61 62 filmUrl=Soup.select(".play_info") 63 Url_list=[] 64 for i in range(len(filmUrl)): 65 href=filmUrl[i].a['href'] 66 Url_list.append(href) 67 return Url_list 68 69 def writeTofile(parsedWebcontent): 70 with open('film.txt','a',encoding='utf-8') as f: 71 for i in range(len(parsedWebcontent)): 72 f.write(parsedWebcontent[i]['fileName']+'\t') 73 f.write(parsedWebcontent[i]['filmCast'] + '\t') 74 f.write(parsedWebcontent[i]['filmIntro'] + '\t') 75 f.write(parsedWebcontent[i]['filmurl'] + '\t') 76 f.write('\n') 77 f.close() 78 79 80 link="https://www.domp4.com/list/6-" 81 for i in range(1,4): 82 url=link + str(i) + ".html" 83 webContent=get_url_content(url) 84 85 if webContent!=False: 86 Content=parse_Web_Content(webContent) 87 writeTofile(Content)
转载于:https://www.cnblogs.com/kevin162726/p/10765321.html
python爬取电影网站信息并写入文件相关推荐
- Python爬取中药网站信息并对其进行简单的分析
开发工具 Python版本:3.5.4 相关模块: 爬虫: import requests from bs4 import BeautifulSoup 词云: from wordcloud impor ...
- python爬取电影网站存储于数据库_Python零基础爬虫教程(实战案例爬取电影网站资源链接)...
前言 好像没法添加链接,文中的链接只能复制到浏览器查看了 这篇是我写在csdn的,那里代码格式支持更好,文章链接 https://blog.csdn.net/d497465762/article/de ...
- python自动爬取更新电影网站_python爬取电影网站信息
一.爬取前提 1)本地安装了mysql数据库 5.6版本 2)安装了Python 2.7 二.爬取内容 电影名称.电影简介.电影图片.电影下载链接 三.爬取逻辑 1)进入电影网列表页, 针对列表的ht ...
- python爬取网上租房信息_用python爬取租房网站信息的代码
自己在刚学习python时写的,中途遇到很多问题,查了很多资料,下面就是我爬取租房信息的代码: 链家的房租网站 两个导入的包 1.requests 用来过去网页内容 2.BeautifulSoup i ...
- python爬取电影网站存储于数据库_python爬虫 猫眼电影和电影天堂数据csv和mysql存储过程解析...
字符串常用方法 # 去掉左右空格 'hello world'.strip() # 'hello world' # 按指定字符切割 'hello world'.split(' ') # ['hello' ...
- python房子代码_用python爬取租房网站信息的代码
自己在刚学习python时写的,中途遇到很多问题,查了很多资料,下面就是我爬取租房信息的代码: 链家的房租网站 两个导入的包 1.requests 用来过去网页内容 2.BeautifulSoup i ...
- python电影系统管理-Python 爬取电影网站的信息【如有重复请管理删帖】
[Python] 纯文本查看 复制代码#!/usr/bin/env python # -*- coding: utf-8 -*- # [url=home.php?mod=space&uid=6 ...
- Python 爬取电影天堂top最新电影
Python爬虫有他无可比拟的优势:语法简单,经常几十行代码就能轻松解决问题,相比于JAVA,C,PHP;第三方库丰富,Python强大而又丰富的第三方库使他几乎可以无所不能.今天我们就来用用Pyth ...
- python爬取小说章节信息用pygame进行数据显示_爬虫不过如此(python的Re 、Requests、BeautifulSoup 详细篇)...
网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本. 爬虫的本质就是一段自动抓取互联网信息的程序,从网络获取 ...
最新文章
- python3教程-终于清楚python3详细教程
- 友盟-上传开发发布证书
- 【树莓派】可能是最简单粗暴的树莓派搭建个人网站教程
- 『数据库』数据库编程(概念性的东西,应用一般,甚至有点过时,用来考试)
- CSS 选择器权重计算规则
- Java笔记-RestTemplate(Java进程)配置代理Fiddler抓包
- webpack在内存生成html,Vue学习之Webpack基本使用小结(十三)
- Google帝国研究——Google的产业构成
- python3几种常见解压压缩包的方法
- Unity Shader 实现透明护盾效果
- vlookup匹配的文字显示0_详解vlookup函数中{1,0}的使用方法,看完后给同事讲讲,秒变大神...
- Dharma勒索软件继续大肆传播,据称已有100多家希腊网站沦陷
- 淘宝商品详情接口(原数据app、h5端)
- 流程图和火车程序Jackson图
- bzoj3875 [Ahoi2014Jsoi2014]骑士游戏
- 华为分析丨汽车行业报告上线,赋能车企业绩增长
- Codeforces 844A
- 哪些食物不能一起吃!!!!
- 牛客小白月赛7 I.新建 Microsoft Office Word 文档
- 如何解决Bat脚本中包含中文,运行乱码
热门文章
- 台式机dp接口_台式机成就3471和战99,哪个更好?对比分析
- proc除了能用于oracle开发_能不能用于mysql开发_Oracle数据库开发(二).Linux下配置使用ProC...
- java的drawstring_java-Graphics.drawString()未绘制
- fullcalendar 显示的时间间隔只有四十五分钟_Linux命令行监控程序,还能实时高亮显示差异,我就选它了...
- 下拉选项框选中之后,通过ajax请求服务器,填充页面其他元素的value值
- js和php获取页面的url信息
- 这些面试题你会吗?Java-类与对象再不了解你就out啦
- 【深度学习】基于Colab Pro的TPU训练模型教程(Tensorflow)
- 快速排序 java 实现
- php页面在线人数,也谈php网站在线人数统计