How to change WebDriver’s IP address

I have already written several articles on how to use WebDriver for web scraping, but I have never touched on the topic of changing WebDriver’s IP address. Nevertheless, this topic is quite crucial when you come to web scraping, and here I’d like to show you an example of using proxies with WebDriver in Python (and you can easily convert it into your language API).

First of all you need a proxy server. You can use any proxy service you like, but if you don’t have one, I would recommend that you consider BestProxyAndVPN (if you’re ready to pay for proxy services). I have tried many proxy services and ended up using this one as the most stable.

Now let’s look at two pieces of code displaying how to make WebDriver send its requests through a proxy.

Using Proxy with Chrome Driver

If you use Selenium WebDriver with the Chrome browser, you can tune it to use a proxy in the following way:

Don’t forget to change the proxy server address and ChromeDriverPath to your values.

Using Proxy with Firefox WebDriver

If you prefer scraping with the Firefox browser, you can cause it to use proxy with the following code:

And again, don’t forget to change the proxy address and port to your values.

EDIT: Here is another way to specify proxy servers for Firefox webdriver (thanks to Curro Pavon):

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值