Python uses proxy IP to access the website

不言
Release: 2018-05-07 14:11:31
Original
5756 people have browsed it

This article mainly introduces the use of proxy IP to access the website in python, which has certain reference value. Now I share it with everyone. Friends in need can refer to it.

The examples are as follows Display:

# -*- coding: UTF-8 -*-
from urllib import request
if __name__ == "__main__":
  #访问网址
  url = 'http://www.whatismyip.com.tw/'
  #这是代理IP
  ip = '27.155.101.233:3128'
  #设置代理ip访问方式,http和https
  proxy = {'http':ip,'https':ip}
  #创建ProxyHandler
  proxy_support = request.ProxyHandler(proxy)
  #创建Opener
  opener = request.build_opener(proxy_support)
  #添加User Angent
  opener.addheaders = [('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0')]
  #安装OPener
  request.install_opener(opener)
  #使用自己安装好的Opener
  response = request.urlopen(url)
  #读取相应信息并解码
  html = response.read().decode("utf-8")
  #打印信息
  print(html)
Copy after login

whatismyip is a website for querying IP. I used 27.155.101.233 for the above code, and the port number is 3128 for this Visit the website

This is the output information:

You can see that 27.155.101.233 has been used This proxy IP accessed whatismyip, but failed to achieve high confidentiality, and the real IP was found by this website.

But for most things like voting, there is still no problem

Related recommendations:

Example sharing of python obtaining proxy IP

The above is the detailed content of Python uses proxy IP to access the website. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!