4
|
1 #!/usr/bin/env python
|
|
2
|
|
3 import io
|
|
4 import urllib2, urllib, httplib
|
|
5 def getListFromFile(file):
|
|
6 idlist=[]
|
|
7 for line in file:
|
|
8 if int(line):
|
|
9 idlist.append(line.strip())
|
|
10 return idlist
|
|
11
|
|
12 def getresult(url):
|
|
13 try:
|
|
14 connection = urllib2.urlopen(url)
|
|
15 except urllib2.HTTPError, e:
|
|
16 return ""
|
|
17 else:
|
|
18 return connection.read().rstrip()
|
|
19
|
9
|
20 def store_result_get(url, outfile):
|
8
|
21 data=getresult(url)
|
|
22 outfile.write(data)
|
|
23 outfile.close()
|
9
|
24
|
|
25 def store_result_post(url, post, outfile):
|
|
26 data = urllib.urlencode(post)
|
|
27 headers={"Content-Type" : "application/x-www-form-urlencoded"}
|
|
28 req = urllib2.Request(url, data, headers)
|
|
29 response = urllib2.urlopen(req)
|
|
30 the_page = response.read()
|
|
31 outfile.write(the_page)
|
|
32 outfile.close()
|