Python uses socks5 of Red Dance Agent to collect examples.
# Python uses the socks5 of Red Dance Agent to collect instances
Reprint: http://helpserver.chiwudaili.com/detail.aspx?id=a73406e4bdcc01ae615b649bf994bfb5
#
Import json
From time import sleep
Import requests
#
Def MyRequestGet (url,decode,proxyIPAndPort):
Print ("MyRequestGet ({0}, {1}, {2}) IN" .format (url,decode,proxyIPAndPort))
Headers = {'User-Agent':' Mozilla/5.0 (X11; Linux x86 / 64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'}
Rel = ""
If (len (proxyIPAndPort) > 0):
Proxies = {'http':' socks5://ip:port','https':'socks5://ip:port'}
Proxies ['http'] = "socks5:// {0}" .format (proxyIPAndPort)
Proxies ['https'] = "socks5:// {0}" .format (proxyIPAndPort)
# print (proxies)
Response = requests.get (url, proxies=proxies)
Rel = response.content.decode (decode)
Else:
Response = requests.get (url)
Rel = response.content.decode (decode)
Print ("MyRequestGet () OUT: {0}" .format (rel))
Return rel
#
Def MyGetPorxyIPAndPortFromChiWuDaiLi (phoneNumber,password):
Rel = ""
While (True):
Try:
Path = 'http://mainserver.chiwudaili.com:8000/api/GetProxyIPsAndPorts.ashx?';
Param = 'UserPhoneNumber= {0} & UserPassword= {1} & Count=1'.format (phoneNumber,password)
Url = "{0} {1}" .format (path,param)
StringJson = MyRequestGet (url,'utf-8', "")
ObjectJson = json.loads (stringJson)
If (objectJson ['Code'] = = 0):
If (objectJson ['Data'] [' State'] = = 0):
For index,value in enumerate (objectJson ['Data'] [' IPs']):
Rel = "{0}: {1}" .format (value ['IP'], value [' Port'])
Return rel
Else:
Print (objectJson ['Data'] [' Error'])
Sleep (5)
Else:
Print (objectJson ['Message'])
Sleep (5)
Except Exception as err:
Print (err)
Sleep (1)
Return rel
#
Def MyMain (phoneNumber,password):
Print ("MyMain () IN")
While (True):
# url = 'http://2018.ip138.com/ic.asp';decode='gb2312';
Url = 'http://helpserver.chiwudaili.com/';decode='utf-8';
# url = 'https://www.baidu.com/';decode='utf-8';
ProxyIPAndPort = MyGetPorxyIPAndPortFromChiWuDaiLi (phoneNumber,password)
Try:
While (True):
If (len (proxyIPAndPort) > 0):
Result = MyRequestGet (url,decode,proxyIPAndPort)
Print (result)
Else:
Print ('Get Proxy IP And Port failed')
Sleep (1)
Except Exception as err:
Print (err)
Finally:
Print ('do nothing')
Sleep (1)
Print ("MyMain () OUT")
#
# MyMain ('your mobile phone number', 'password')
MyMain ('13000000000)
#