Reputation: 43
I am currently writing a scraper for testing want to access the site with a different IP, I have found a lot of information about using a proxy and tried this several times, however when I access a site that shows the IP used in the request, it shows the IP of my computer.
I am using a free Proxy I found online.
Here is my code:
import requests
proxy = {'SOCKS5': '24.145.195.60:27595'}
response = requests.get('http://www.whatsmyip.de/', proxies=proxy)
print response
Any help is greatly appreciated!
Upvotes: 3
Views: 1349
Reputation: 13693
You need to define a proxy for the HTTP
and or a HTTPS
protocol. I'm not sure if requests
works with SOCKS
protocol yet
This works for me.
import requests
import bs4
proxy = {"http": "115.227.195.213"}
response = requests.get('http://www.whatsmyip.de/', proxies=proxy)
soup = bs4.BeautifulSoup(response.text)
print soup.h3.text
Note: It uses the bs4 module to print the ip and I used a proxy server that is HTTP
compatible
Upvotes: 2