from urllib import request
from bs4 import BeautifulSoup
if __name__ == "__main__":
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'
}
proxies = {
'https': 'https://127.0.0.1:7890',
'http': 'http://127.0.0.1:7890'
}
google_url = 'https://www.google.com'
opener = request.build_opener(request.ProxyHandler(proxies))
request.install_opener(opener)
req = request.Request(google_url, headers=headers)
response = request.urlopen(req,timeout=100000)
print(response.read().decode())