Skip to content

通过http代理获取页面内容

python
import requests

def get_html(url):
	headers = {
		"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.27"
	}
	proxies = {'https':'127.0.0.1:10809', 'http':'127.0.0.1:10809'}
	resp = requests.get(url, headers=headers, proxies=proxies)
	return resp.content.decode()

url = 'https://www.economist.com/europe/2022/09/08/meet-the-hard-right-party-likely-to-win-italys-election'
html = get_html(url)
print(html)

Released under the MIT License.