-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcollection.py
29 lines (23 loc) · 894 Bytes
/
collection.py
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
#!/usr/bin/env python
import urllib2
import urllib
class Collection:
__referer = "http://www.google.com/"
__useragent = "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.149 Safari/537.36"
def __init__(self,url,referer=__referer,ua=__useragent):
self.__ua=ua
self.__referer=referer
if self.__get_content(url):
self.content=self.__get_content(url)
else:
self.content=""
def __get_content(self,url):
header={"Accept": "text/plain","Connection":"close","User-Agent":self.__ua,"Referer":self.__referer}
req = urllib2.Request(url,headers=header)
try:
page = urllib2.urlopen(req,timeout=10)
return page.read()
except:
return False
if __name__ == "__main__":
print "This is not a Direct execut program"