I am trying to access a proxy, that I have ping multiple times and is online, to do a search.
import requests
import re
s = requests.Session()
s.proxies = {'http': 'http://11.22.33.4455'}
r = s.get('https://www.iplocation.net/find-ip-address')
data = r.text
regex = r"1.2.3.45" # Proxy IP
regex2 = r"6.7.8.99" # My IP
matches = re.findall(regex, data)
matches2 = re.findall(regex2, data)
print(matches)
print(matches2) # Always prints out my current IP and not my proxy
This is my code. I use regular expressions to search the html code for mentions of the IP and it always only returns my current IP. I tried different websites that tell me my IP and everyone of them returns my current IP and not my proxy. Any suggestion on what I am doing wrong.
In order to use proxies in the requests Python library, you need to create a dictionary that defines the HTTP, HTTPS, and FTP connections. This allows each connection to map to an individual URL and port. This process is the same for any request being made, including GET requests and POST requests.
To use a proxy in Python, first import the requests package. Next create a proxies dictionary that defines the HTTP and HTTPS connections. This variable should be a dictionary that maps a protocol to the proxy URL. Additionally, make a url variable set to the webpage you're scraping from.
Your proxy is http while your request address is a https. You need to have another proxy for https requests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With