python 小脚本 通过关键词在百度网盘 搜索 高清电影并生成html浏览
来源:互联网 发布:小册子打印软件 编辑:程序博客网 时间:2024/04/29 04:32
比较屌丝,看电影经常用百度云网盘,所以写个脚本方便查看。
保持脚本为
baidu.py
,然后python baidu.py -h
查看帮助。-p
:指定第几页;-k
:关键词把符合的电影最后生成Html文件然后浏览(文件位置自己再修改下或者改成动态的吧)。
设置alias:
alias baidu="python baidu.py"
,然后 在命令行中 执行baidu -p 1 -k 2016
脚本地址:https://github.com/kute/purepythontest/blob/master/test/get_film_from_baidu.py
脚本:
#! /usr/bin/env python# -*- coding: utf-8 -*-# __author__ = 'kute'# __mtime__ = '16/10/22 17:49'"""关键词 过滤 查看 百度网盘的高清电影太懒了我"""import argparseimport requestsfrom bs4 import BeautifulSoupimport dominatefrom dominate.tags import meta, div, table, tr, td, aimport webbrowserclass GetFilm(object): def __init__(self, page=1, keyword="2016"): self.page = page or 1 self.keyword = keyword self.baiduurl = "http://www.baiduyun.me/forum.php?mod=forumdisplay&fid=99&page={}" self.baidufile = "/Users/kute/Desktop/baidu.html" def request(self): print("========1. Curent page is {} and the keyword is {}.========".format(self.page, self.keyword)) res = requests.get(self.baiduurl.format(self.page)) parse = BeautifulSoup(res.text, "html.parser") tbodylist = parse.select("tbody[id^='normalthread']") filmlist = [] for tbody in tbodylist: parse2 = BeautifulSoup(str(tbody.tr.th), "html.parser") a = parse2.select_one("a[class='s xst']") if self.keyword: if a.string.find(self.keyword) != -1: filmlist.append((a["href"], a.string)) else: filmlist.append((a["href"], a.string)) print("========2. Finish scrapy the page and begin generate the html:{}.========".format(self.baidufile)) self.generate_html(filmlist) def generate_html(self, filmlist): doc = dominate.document(title='Dominate your HTML') with doc.head: meta({"http-equiv": "Content-Type", "content": "text/html; charset=UTF-8"}) with doc: with div(): with table(): for url, text in filmlist: with tr(): with td(): a(text, href=url, target="_blank") with open(self.baidufile, "w") as f: f.write(doc.render()) print("========3. All finished, have a look please.========") webbrowser.open("file://{}".format(self.baidufile), new=0, autoraise=True)def main(): parse = argparse.ArgumentParser(description="Generate films file") parse.add_argument("-k", "--keyword", help="the film year you want to see, default 2016") parse.add_argument("-p", "--page", help="next page loop, default 1") args = parse.parse_args() g = GetFilm(args.page, args.keyword) g.request()if __name__ == '__main__': main()
- 效果:
0 0
- python 小脚本 通过关键词在百度网盘 搜索 高清电影并生成html浏览
- 在Python中发送广播消息并接收所有客户端响应的小脚本
- 一些python小脚本
- Python字典小脚本
- python统计小脚本
- python小脚本
- 怎么在百度里通过关键词搜索到自己的网站
- Python小脚本 001 备份文件
- 【Python】一键式发邮件小脚本
- python文件命名小脚本
- python小脚本2则
- python 备份文件的小脚本
- 《鞭/甜蜜皮鞭》高清电影在线观看 - 百度影音 - 爱情电影
- matlab生成多个文件夹,并根据文件的文件名粘贴进文件夹的小脚本
- HTML刷新当前页面的小脚本
- python request库 百度360关键词搜索提交
- python爬虫抓取多关键词搜索的百度图片
- python写的小巧的(14行有效代码)随机密码生成小脚本工具
- 常用数论算法
- 172. Factorial Trailing Zeroes
- Linux笔记
- 通配符映射
- 机器学习基石第一讲:PLA
- python 小脚本 通过关键词在百度网盘 搜索 高清电影并生成html浏览
- [C#]六十甲子纳音 v1.0 By:LESLIE
- 对Rxjava和Retrofit的一次封装使用
- HDU 3605 Escape
- 浅谈JVM JRE JDK的区别
- MySQL基础之表操作 索引 约束 视图等介绍
- poj 1328 贪心
- springMVC异常和处理
- 带缓存和不带缓存操作和进程总结