Created
September 4, 2018 20:24
-
-
Save nikhilkumarsingh/998b51b030e2f3c0efe00f37634e9e9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Are these free proxies? Can we scrape google? Are there roratibg obe?