(1) 如果我们一直用同一个IP去请求同一个网站上的网页,久了之后可能会被该网站服务器屏蔽,因此我们可以使用代理IP来发起请求,代理实际上指的就是代理服务器
(2) 当我们使用代理IP发起请求时,服务器端显示的是代理IP的地址,即使被屏蔽了,我们可以换一个代理IP继续爬取,代理IP获取页面:https://www.xicidaili.com/

这里我在本地搭建了一个代理,它运行在 8888 端口,我们使用这个代理来请求服务器:

import requests

proxies = {
    "http": "127.0.0.1:8888",
    "https": "127.0.0.1:8888"
}

req = requests.get("https://www.baidu.com/", proxies=proxies)
print(req.status_code)

 

 

 

 

 

 

 

    

相关文章:

  • 2022-12-23
  • 2021-12-23
  • 2021-08-27
  • 2021-11-28
  • 2021-12-10
  • 2021-08-30
  • 2021-11-10
猜你喜欢
  • 2021-12-13
  • 2021-11-28
  • 2021-11-15
  • 2021-08-22
  • 2022-01-01
相关资源
相似解决方案