-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetQiReLinks.py
More file actions
75 lines (60 loc) · 2.23 KB
/
GetQiReLinks.py
File metadata and controls
75 lines (60 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import sgmllib
import urllib2
from pprint import pprint
from bs4 import BeautifulSoup
class PageParser(sgmllib.SGMLParser):
def __init__(self, aPrefix):
# inherit from the SGMLParser class
sgmllib.SGMLParser.__init__(self)
# create a list this will store all the links found
self.links = []
self.prefix = aPrefix;
def unknown_starttag(self, tag, attrs):
for key, value in attrs:
#print "key and value", key, value
if key == "href" and value.startswith('/videos/'):
self.links.append(self.prefix + value)
class PageParserForBaidhHD(sgmllib.SGMLParser):
def __init__(self):
# inherit from the SGMLParser class
sgmllib.SGMLParser.__init__(self)
# create a list this will store all the links found
self.links = []
def unknown_starttag(self, tag, attrs):
print "unknown tag start " + tag
for key, value in attrs:
print key , value
if key.lower() == "param_url":
value = unicode(value, 'utf-8')
print value
self.links.append(value)
def getGiRenList(vedioUrl):
bdhdList = []
sock = urllib2.urlopen(vedioUrl)
# make sure the string that is going to be parsed is 8-bit ascii
if sock.info().dict['content-type'] == 'text/html':
parser = PageParser("http://www.qire123.com/")
parser.feed(sock.read());
parser.close();
bdhdList = parser.links
return bdhdList
def getBaiduHDAddress(vedioUrl):
bdhdList = []
sock = urllib2.urlopen(vedioUrl)
if sock.info().dict['content-type'] == 'text/html':
# page = sock.read()
soup = BeautifulSoup(sock)
soup.prettify()
for anchor in soup.findAll('object'):
print anchor['href']
return bdhdList
def main():
urlAddress = "http://www.qire123.com/occident/yifanzhuizongdiyiji/";
#pprint (getGiRenList(urlAddress));
list1 = getGiRenList(urlAddress);
list1.reverse();
for aUrl in list1:
getBaiduHDAddress(aUrl);
#pprint (txtlist)
if __name__ == '__main__':
main();