Created
April 1, 2014 05:21
-
-
Save xdqi/9908156 to your computer and use it in GitHub Desktop.
Print all magnet links on a KTXP search page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Using: getktxp.py [KTXP Search Page URL] | |
# TODO: | |
# 1. Merge it with lixian-cli | |
# 2. Support Multi Pages (I did not implement that because typical anime series has less than 30 episodes) | |
import sys | |
from bs4 import BeautifulSoup | |
import requests | |
import urllib | |
import re | |
from HTMLParser import HTMLParser | |
#import os | |
z = requests.get(sys.argv[1]) | |
y = BeautifulSoup(z.text) | |
x = y.select('td.ltext.ttitle') | |
for w in x: | |
a = requests.get('http://bt.ktxp.com/%s' % w.select('a')[1]['href']) | |
b = BeautifulSoup(a.text) | |
c = b.select('div.right.clear script')[0].text | |
d = HTMLParser.unescape.__func__(HTMLParser, urllib.unquote(c)) | |
e = re.findall(r'"(magnet:.+)"', d)[0] | |
print e | |
#os.system('python lixian-cli.py add %s' % e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment