forked from smilejay/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisitBlog.py
More file actions
58 lines (45 loc) · 1.36 KB
/
VisitBlog.py
File metadata and controls
58 lines (45 loc) · 1.36 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
#! /usr/bin/python3
# -*- coding: utf-8 -*-
'''
Created on 2011-04-06
@description: use multithreading to visist some of my blog pages
@author: http://smilejay.com/
'''
import sys
import threading
import urllib.request
urls = ['kvm_theory_practice/',
'about/',
'i_will_laugh_at_the_world/'
]
visitTimesPerPage = 10
def usage():
print('Usage:', sys.argv[0], 'host')
def main(argv):
host = argv[1]
if host == '':
usage()
sys.exit(2)
else:
for i in range(visitTimesPerPage):
for url in urls:
visitPageThread = VisitPageThread(url + str(i), host, url)
visitPageThread.start()
class VisitPageThread(threading.Thread):
def __init__(self, threadName, host, url):
threading.Thread.__init__(self, name=threadName)
self.host = host
self.url = url
def run(self):
url = self.host + self.url
req = urllib.request.Request(url)
req.set_proxy('companyname.com:911', 'http')
# you may set you proxy here.
try:
doc = urllib.request.urlopen(req).read()
print(doc)
except Exception as e:
print("urlopen Exception : %s" % e)
if __name__ == '__main__':
sys.argv.append('http://smilejay.com/')
main(sys.argv)