Skip to content

Instantly share code, notes, and snippets.

@pocketwalker
Forked from anonymous/watchop.py
Created September 1, 2012 01:06
Show Gist options
  • Save pocketwalker/3562159 to your computer and use it in GitHub Desktop.
Save pocketwalker/3562159 to your computer and use it in GitHub Desktop.
making it easy to watch one piece
#!/usr/bin/python
#coding=utf-8
from bs4 import BeautifulSoup
import sys, re
import urllib, urllib2
import xml.etree.ElementTree as ET
import webbrowser
#import codes, Queue, threading, time
def spider(net):
src = urllib.urlopen(net).read()
parser = BeautifulSoup(src)
return parser
#spider http://www.xiaozhan.net/onepiece/ to get the number'th page
def spider_xiaozhan(html, number):
parser = spider(html)
td = parser.find('div', 'left-part').findAll('td')
if (number*3-2)+1 >= (len(td)-3) or number == 0:
print('抱歉,目前没有这一集,可以期待')
else:
print('稍等,正在打开您的浏览器...')
dist = td[number * 3 - 2].a['href']
return dist
return None
#spider http://www.letv.com/ptv/pplay/5330/**.html to get the video code
def spider_letv(html):
parser = spider(html)
input = parser.find('div', 'K-Info').findAll('input')
value = input[4]['value']
return value
#open webbrowser to watch op videos
def open_browser(url):
webbrowser.open_new(url)
pattern = re.compile(r'\D', re.I | re.X)
while True:
print "感谢使用脚本!您要收看最受人类欢迎动漫《海贼王》的第几集呢?"
print "虽然目前暂不支持收看多集,但是《海贼王》的一集不简单呢!马上输入一个非负整数来体验吧!(例如1,123)输入任何非法字符即退出,浏览器打开后按ctrl-C退出"
cmd = raw_input('episode: ')
m = pattern.search(cmd)
if m:
print('正在退出...')
sys.exit()
else:
geturl = int(cmd)
a = spider_xiaozhan('http://www.xiaozhan.net/onepiece/', geturl)
if a == None:
sys.exit()
b = spider_letv(a)
open_browser(b)
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment