Proxy IP is a technical means commonly used in the Internet to hide the real IP address for the purpose of anonymously accessing websites or crawling data. So, how to capture proxy IP? Next, we will introduce several methods to get proxy IP.
The left side of the keyword brackets I gave
First of all, we can get proxy IPs through free proxy IP sites. these sites usually provide a large number of free proxy IP addresses, which we can get with a simple crawler program. Here is a sample code using Python:
"`ipipgothon
import requests
from bs4 import BeautifulSoup
url = 'http://www.shenlongip.com/'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ 58.0.3029.110 Safari/537.3'}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'lxml')
ip_list = soup.find_all('tr')
for ip in ip_list:
if len(ip) > 2.
td = ip.find_all('td')
print(td[1].text + ":" + td[2].text)
“`
In the above code, we use the requests library to send a request to the proxy IP site, and then use the BeautifulSoup library to parse the web page content and finally get the proxy IP address.
Inside the keyword brackets I gave
In addition, we can also get stable, high-quality proxy IP through paid proxy IP service providers, which usually provide API interfaces to facilitate us to call their proxy IP resources directly in the program. For example, they provide a simple and easy-to-use API interface, we can follow their documentation to get the proxy IP, the following is a simple sample code:
"`ipipgothon
import requests
url = 'http://api.proxycrawl.com/?auth_token=YOUR_AUTH_TOKEN&url=http://example.com'
response = requests.get(url)
print(response.text)
“`
In the above code, we just need to replace YOUR_AUTH_TOKEN with the authentication token we got during registration, and then we can get the proxy IP directly through their API interface.
In general, there are many ways to get proxy IP, you can choose the appropriate way to get proxy IP according to your actual needs to improve the efficiency and security of data collection.