mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
added random proxy request script
This commit is contained in:
parent
e9406f42ff
commit
020eb9e691
20
Proxy-Request/README.md
Normal file
20
Proxy-Request/README.md
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# Web proxy request application using Python
|
||||||
|
|
||||||
|
|
||||||
|
A quick, reliable and random Web Proxy request application using Python.
|
||||||
|
|
||||||
|
## 3rd party libraries used
|
||||||
|
|
||||||
|
- requests
|
||||||
|
|
||||||
|
- bs4
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```
|
||||||
|
from proxy_request import proxy_request
|
||||||
|
|
||||||
|
r = proxy_request('get', "https://httpbin.org/ip")
|
||||||
|
|
||||||
|
print(r.json())
|
||||||
|
```
|
26
Proxy-Request/proxy_request.py
Normal file
26
Proxy-Request/proxy_request.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
from random import choice
|
||||||
|
|
||||||
|
|
||||||
|
def get_proxy():
|
||||||
|
url = "https://www.sslproxies.org/"
|
||||||
|
r = requests.get(url)
|
||||||
|
soup = BeautifulSoup(r.content, 'html5lib')
|
||||||
|
return {'https': choice(list(map(lambda x:x[0]+':'+x[1], list(zip(map(lambda x:x.text, soup.findAll('td')[::8]),
|
||||||
|
map(lambda x:x.text, soup.findAll('td')[1::8]))))))}
|
||||||
|
|
||||||
|
def proxy_request(request_type, url, **kwargs):
|
||||||
|
while 1:
|
||||||
|
try:
|
||||||
|
proxy = get_proxy()
|
||||||
|
print(f"Using proxy {proxy['https']}")
|
||||||
|
response = requests.request(request_type, url, proxies=proxy, timeout=5, **kwargs)
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
r = proxy_request('get', "https://www.youtube.com/IndianPythonista")
|
Loading…
Reference in New Issue
Block a user