123456789101112131415from fake_useragent import UserAgent # 下载:pip install fake-useragentimport requestsua = UserAgent() # 实例化,需要联网但是网站不太稳定-可能耗时会长一些print(ua.random) # 随机产生headers = { 'User-Agent': ua.random # 伪装 }print(headers)# 请求if __name__ == '__main__': url = 'https://www.baidu.com/' response = requests.get(url, headers=headers ,proxies={"http":"117.136.27.43"}) print(response.status_code) 12345678proxies = { "http": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": "t18552632261285", "pwd": "bjnrabj3", "proxy": "a892.kdltps.com:15818"}, # "https": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": "t18637964583060", "pwd": "7wu91jnb", "proxy": "s1000.kdltps.com:15818"},} resp = requests.get(url, headers=headers,proxies=proxies)print(resp.status_code)