When we visit some target websites, we need to use cookies to log in. The server will think that you are a logged in user, so it will return you a logged in content. Therefore, if a verification code is required, a cookie solution with a verification code login can be used. In addition, sometimes the website we visit needs to complete a series of instructions, especially with the proxy, it needs the same IP to complete these instructions, then we need to set a random number to solve.

We can share some Settings about random numbers for your reference. Because we are added to the agent, so the agent also hang up to share with you to exchange learning.

#! -* -encoding: UTF-8 -* -import requests import random import requests. Adapters # "https://httpbin.org/ip", "https://httpbin.org/headers", "https://httpbin.org/user-agent", ] # proxyHost = "t.16yun.cn" proxyPort = "31111" # proxyUser = "username" proxyPass = "password" proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % { "host": proxyHost, "port": proxyPort, "user": ProxyUser, "pass": proxyPass,} # Set HTTP and HTTPS access to proxies = {" HTTP ": proxyMeta, "HTTPS ": } # set headers = random. Randint (1, 10000) headers = {"Proxy ": str(tunnel)} class HTTPAdapter(requests.adapters.HTTPAdapter): def proxy_headers(self, proxy): headers = super(HTTPAdapter, self).proxy_headers(proxy) if hasattr(self, 'tunnel'): Headers [' proxy-tunnel '] = self. Tunnel return headers # for I in range(3): S = requests. Session () a = HTTPAdapter() # access_request a.tunnel = tunnel s.ount ('https://', a) r = s.get(url, proxies=proxies) print r.textCopy the code