from grab import Grab import re RE_PROXY_LINE re compile def main kwar

 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
from grab import Grab
import re
RE_PROXY_LINE = re.compile(r'^(?:\d{1,3}\.){3}\d{1,3}:\d{1,4}$')
def main(**kwargs):
g = Grab()
g.go('http://account.fineproxy.org/')
g.set_input('log', '***')
g.set_input('pass', '****')
g.submit()
if not g.doc.select('//a[@href="/profile/logout/"]').exists():
raise Exception('Unexpected response')
post = {
'templ': '{ip}:{port}',
'type': 'httpip',
'format': 'text',
}
g.go('http://account.fineproxy.org/proxy/', post=post)
rows = g.response.body.splitlines()
if RE_PROXY_LINE.match(rows[0]) and RE_PROXY_LINE.match(rows[1]):
g.response.save('/web/proxy.txt')
else:
raise Exception('Unexpected response')