python 电影下载链接爬虫
V1.0
功能:从比较知名的几个电影下载网站爬取下载链接,并自动打印出来:
代码:
# -*- coding: utf8 -*-
from bs4 import BeautifulSoup
import requests, lxml
from urllib.parse import quote
import re def get_name():
while 1:
moviename = input('请输入要查找的电影名\n->')
moviename_quote = quote(moviename.encode('gb2312'))
get_url_from_ygdy(moviename_quote)
get_url_from_bttiantang(moviename)
get_url_from_dytt(moviename_quote) def get_url_from_ygdy(moviename):
baseurl = 'http://s.dydytt.net/plus/search.php?kwtype=0&keyword='
url = baseurl + str(moviename)
content = BeautifulSoup(requests.get(url).content.decode('gb2312', 'ignore'), 'lxml')
first_page = content.find_all('td', width="")
movie_infos = content.find_all('td', width="55%")
if movie_infos.__len__() == 0:
print('查无此电影,请检查后重试')
return
else:
print('阳光电影搜索结果:')
if first_page.__len__() == 0:
for movie_info in movie_infos:
get_info(movie_info, moviename)
else:
last_page_url = first_page[1].find('a').get('href') + '"'
pattern = re.compile('PageNo=(.*?)"')
pnt = re.findall(pattern, last_page_url)
for i in range(int(pnt[0])):
print('第', i + 1, '页:')
page_url = url + '&PageNo=' + str(i + 1)
pagecontent = BeautifulSoup(requests.get(page_url).content.decode('gb2312', 'ignore'), 'lxml')
movie_infos = pagecontent.find_all('td', width='55%')
for movie_info in movie_infos:
get_info(movie_info, moviename) def get_info(movie_info, name):
movie_url = movie_info.find('a').get('href')
moviename = movie_info.text
if '游戏' not in name and '游戏' in moviename:
return
else:
print('电影名:', moviename)
url = 'http://www.ygdy8.com' + movie_url
info = BeautifulSoup(requests.get(url).content.decode('gbk', 'ignore'), 'lxml')
download = info.find_all('td', style="WORD-WRAP: break-word")
print('下载链接:')
if download.__len__() == 1:
print(download[0].find('a').string)
else:
for each in range(download.__len__()):
print('链接', each + 1, ':', download[each].find('a').string)
print('\n') def get_url_from_bttiantang(moviename):
baseurl = 'http://www.bttiantang.com/s.php?q=' + str(moviename)
page_content = requests.get(baseurl).content.decode('utf8', 'ignore')
pattern = re.compile('</b>条<b>(.*?)</b>')
pagenum_info = re.findall(pattern, page_content)
page_content = BeautifulSoup(page_content, 'lxml')
content = page_content.find_all('p', class_="tt cl")
if content.__len__() == 0:
print('查无此电影,请检查后重试')
return
else:
print('BT天堂搜索结果:')
if pagenum_info.__len__() == 0:
for each in content:
get_movieinfo(each, moviename)
else:
for i in range(int(pagenum_info[0])):
print('第', i + 1, '页:')
page_url = baseurl + '&PageNo=' + str(i + 1)
page_content = BeautifulSoup(requests.get(page_url).content.decode('utf8', 'ignore'), 'lxml')
content = page_content.find_all('p', class_="tt cl")
for each in content:
get_movieinfo(each, moviename) def get_movieinfo(movie_content, name):
url = 'http://www.bttiantang.com/' + movie_content.find('a').get('href')
moviename = movie_content.text
if '游戏' not in name and '游戏' in moviename:
return
print('电影名:', moviename)
info = BeautifulSoup(requests.get(url).content.decode('utf8', 'ignore'), 'lxml')
links = info.find_all('div', class_='tinfo')
print('下载链接:')
i = 0
for each in links:
i += 1
print('链接' + str(i) + ':')
print('http://www.bttiantang.com' + each.find('a').get('href')) def get_url_from_dytt(moviename):
baseurl = 'http://www.dytt.com/search.asp?searchword=' + str(moviename)
content = requests.get(baseurl).content.decode('gbk', 'ignore')
pattern = re.compile('下一页.*?href.*?page=(.*?)&')
result = re.findall(pattern, content)
content = BeautifulSoup(content, 'lxml')
items = content.find_all('p', class_='s1')
if items.__len__() == 1:
print('查无此电影,请检查后重试')
return
else:
print('电影淘淘搜索结果:')
if result.__len__() == 0:
for i in range(items.__len__() - 1):
get_movieinfo_from_dytt(items[i + 1], moviename)
else:
for i in range(int(result[0])):
print('第', i + 1, '页:')
url = baseurl + '&page=' + str(i + 1)
page_content = BeautifulSoup(requests.get(url).content.decode('gbk', 'ignore'), 'lxml')
items = page_content.find_all('p', class_='s1')
for i in range(items.__len__() - 1):
get_movieinfo_from_dytt(items[i + 1], moviename) def get_movieinfo_from_dytt(item, name):
moviename = item.find('a').text
movieurl = 'http://www.dytt.com' + item.find('a').get('href')
if '游戏' not in name and '游戏' in moviename:
return
print('电影名:', moviename)
pagecontent = requests.get(movieurl).content.decode('gbk', 'ignore')
links = re.findall(re.compile('ed2k:(.*?)\|/'), pagecontent)
i = 0
print('下载链接:')
if links.__len__() != 0:
for link in links:
i += 1
print('链接' + str(i) + ':', 'ed2k://|file|' + link + '|/')
else:
links = re.findall(re.compile('http:(.*?)torrent'), pagecontent)
if links.__len__() != 0:
for link in links:
i += 1
print('链接' + str(i) + ':', 'http:' + link + 'torrent')
else:
links = re.findall(re.compile('ftp:(.*?)mkv'), pagecontent)
for link in links:
i += 1
print('链接' + str(i) + ':', 'ftp:' + link + 'mkv') if __name__ == '__main__':
get_name()
运行结果:
python 电影下载链接爬虫的更多相关文章
- Java爬虫爬取网站电影下载链接
之前有看过一段时间爬虫,了解了爬虫的原理,以及一些实现的方法,本项目完成于半年前,一直放在那里,现在和大家分享出来. 网络爬虫简单的原理就是把程序想象成为一个小虫子,一旦进去了一个大门,这个小虫子就像 ...
- 使用htmlparse爬虫技术爬取电影网页的全部下载链接
昨天,我们利用webcollector爬虫技术爬取了网易云音乐17万多首歌曲,而且还包括付费的在内,如果时间允许的话,可以获取更多的音乐下来,当然,也有小伙伴留言说这样会降低国人的知识产权保护意识,诚 ...
- 使用htmlparser爬虫技术爬取电影网页的全部下载链接
昨天,我们利用webcollector爬虫技术爬取了网易云音乐17万多首歌曲,而且还包括付费的在内,如果时间允许的话,可以获取更多的音乐下来,当然,也有小伙伴留言说这样会降低国人的知识产权保护意识,诚 ...
- 一篇文章教会你利用Python网络爬虫获取电影天堂视频下载链接
[一.项目背景] 相信大家都有一种头疼的体验,要下载电影特别费劲,对吧?要一部一部的下载,而且不能直观的知道最近电影更新的状态. 今天小编以电影天堂为例,带大家更直观的去看自己喜欢的电影,并且下载下来 ...
- Python 爬虫的工具列表 附Github代码下载链接
Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门 https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6E ...
- 【Python项目】简单爬虫批量获取资源网站的下载链接
简单爬虫批量获取资源网站的下载链接 项目链接:https://github.com/RealIvyWong/GotDownloadURL 1 由来 自己在收集剧集资源的时候,这些网站的下载链接还要手动 ...
- Python爬虫个人记录(二) 获取fishc 课件下载链接
参考: Python爬虫个人记录(一)豆瓣250 (2017.9.6更新,通过cookie模拟登陆方法,已成功实现下载文件功能!!) 一.目的分析 获取http://bbs.fishc.com/for ...
- Python网络爬虫笔记(二):链接爬虫和下载限速
(一)代码1(link_crawler()和get_links()实现链接爬虫) import urllib.request as ure import re import urllib.parse ...
- Python 爬虫 Vimeo视频下载链接
python vimeo_d.py https://vimeo.com/228013581 在https://vimeo.com/上看到稀罕的视频 按照上面加上视频的观看地址运行即可获得视频下载链接 ...
随机推荐
- van Emda Boas
van Emda Boas维护了一个整数集合[0,Max)(无重复),其中Max必须等于2的正整数次幂.它支持以下操作:(1)插入一个数字;(2)删除一个数字:(3)询问某一个数字在不在这个集合中:( ...
- [转自老马的文章]用MODI OCR 21种语言
作者:马健邮箱:stronghorse_mj@hotmail.com发布:2007.12.08更新:2012.07.09按照<MODI中的OCR模块>一文相关内容进行修订2012.07.0 ...
- C语言程序设计现代方法_基本类型(第七章)
C语言支持两种不同的数值类型,整数类型,浮点类型. C语言的整数类型有不同的尺寸.int类型通常为32位,但在老的CPU上可能是16位.有些可能是64位. 因此,int型如果在16位CPU上最大值就是 ...
- 数据库分库分表(sharding)
地址: http://blog.csdn.net/column/details/sharding.html
- pfx,cer转pem,并对通过pem文件进行签名与验签
因为PHP无法读取.pfx文件,所以可以先转换为.pem文件然后在读取里面的数据,可以读取.cer文件,为了两方面统一,就都换成.pem然后再进行加签和验签. sign.php <?php de ...
- hibernate对象关系实现(四)继承实现
继承实现方式分为三种:subclass; joined-subclass;union-subclass a.类中体现 b.库中体现分为三种: b.1:一种方式:人和学生公用一张表,添加一个辨别字段 ...
- hdu5406 CRB and Apple dp+两个LIS
题意转换为:给定n个数,求两个最长的不相交的LIS. 先说经典题一个LIS的nlogn做法.枚举当前数,若比末尾数大,插入末尾,否则二分查找,插入合适位置. 通过此题,我们有了一个用树状数组或线段树+ ...
- Linux 注意
1. 赋值运算符= 左右之间不能加空格, 其余的都可以加空格, 而这种限制在以下情况, 可以使用空格 let "n = $1" 虽然也是赋值语句, 但是可以使用空格
- bootstrap学习笔记<十一>(导航条)
基础导航条.样式:class="navbar navbar-default",属性:role="navigation" <div class=" ...
- 2 CSS
2 CSS CSS基础 html 在一个网页中负责的事情是一个页面的结构css(层叠样式表) 在一个网页中主要负责了页面的数据样式. 编写css代码的方式: 第一种: 在style标签中编写c ...