Skip to content

Commit

Permalink
Moving Selenium integratiosn to a new DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahDrucker committed Jul 10, 2019
0 parents commit 2788c34
Show file tree
Hide file tree
Showing 15 changed files with 734 additions and 0 deletions.
87 changes: 87 additions & 0 deletions csharp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
## <img src="https://smartproxy.com/wp-content/themes/smartproxy/images/smartproxy-logo.svg" alt="" width="200" height="50">

### Disclaimer

Selenium is a browser automation tool. This particular repository only covers Selenium setup for C# based programming language.

To continue further development with this tool, make sure to read their [documentation](https://seleniumhq.github.io/selenium/docs/api/dotnet/index.html) for C#.

*Unfortunately, Selenium itself does not support `username:password` authentication for `HTTP/HTTPs` proxies, thus you will need to have your IP whitelisted.*

You can do that by following guidlines listed [here](http://help.smartproxy.com/article/how-to-manage-whitelisted-ips/).

### Prerequisites

To run these particular examples, we used Visual Studio 19 to download Webdrivers and Selenium package itself using C# NuGet:

* [Visual Studio with Visual Basic](https://docs.microsoft.com/en-us/visualstudio/ide/quickstart-visual-basic-console?view=vs-2019)

If you are using something else, you will need to download these packages seperately:

- [Selenium](https://www.seleniumhq.org/download/)
- [Chrome WebDriver](https://sites.google.com/a/chromium.org/chromedriver/downloads)
- [Firefox WebDriver](https://github.com/mozilla/geckodriver/releases)

Note that you need to have at least one of the above drivers to continue your progress.

### Installation

This particular code was built with [Visual Studio with Visual Basic](https://docs.microsoft.com/en-us/visualstudio/ide/quickstart-visual-basic-console?view=vs-2019) which will be used to build and launch the application.

You can run it using these steps:

1. Create a new Console Application.
2. Using a terminal of your choice navigate to the projects directory.
3. Run the cURL command to download the code or copy it directly from the repository by clicking on the preferred WebDriver hyperlink above.

[*Firefox*](https://raw.githubusercontent.com/Smartproxy/Smartproxy/master/selenium/csharp/firefox/example.cs)

```
curl https://raw.githubusercontent.com/Smartproxy/Smartproxy/master/selenium/csharp/firefox/example.cs > example.cs
```

<img src="https://i.imgur.com/pdoz0b9.png">

[*Chrome*](https://raw.githubusercontent.com/Smartproxy/Smartproxy/master/selenium/csharp/chrome/example.cs)

```
curl https://raw.githubusercontent.com/Smartproxy/Smartproxy/master/selenium/csharp/chrome/example.cs > example.cs
```

<img src="https://i.imgur.com/NvGcgpL.png">

4. You should see a new file named example.cs in your project folder.

### Configuration

To configure the proxy, simply change the following string in the code depending on the WebDriver:

*Firefox*

```
HttpProxy = "gate.smartproxy.com:7000"
```

*Chrome*
```
HttpProxy = "http://gate.smartproxy.com:7000"
```

<img src="https://i.imgur.com/R0CPyut.png">

### Testing

If everything is done correctly, after running the code, selected WebDriver will apear with a new IP from the proxy service. You will also get a printed output of the IP in the Console:

<img src="https://i.imgur.com/kQOZsn9.png">

## How to get started with Smartproxy?
[<img src="https://smartproxy.com/wp-content/uploads/2019/04/How-to-buy-Smartproxy-plans-now.svg">](https://dashboard.smartproxy.com/register)
<br><br><center>Accepted payment methods:
<br><img src="https://smartproxy.com/wp-content/uploads/2018/09/payment-methods-smartproxy-residential-rotating-proxies.svg" alt="" width="250" height="50"></center>

## Contacts
Email - [email protected]
<br><a href="https://smartproxy.com">Live chat 24/7</a>
<br><a href="https://join.skype.com/invite/bZDHw4NZg2G9">Skype</a>
<br><a href="https://t.me/smartproxy_com">Telegram</a>
34 changes: 34 additions & 0 deletions csharp/chrome/example.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

class Program
{
static void Main(string[] args)
{
ChromeOptions options = new ChromeOptions();

var proxy = new Proxy
{
Kind = ProxyKind.Manual,
IsAutoDetect = false,
HttpProxy = "http://gate.smartproxy.com:7000"
};
options.Proxy = proxy;

IWebDriver driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("http://ip.smartproxy.com/");
var getBody = driver.FindElement(By.TagName("body"));
var getBodyText = getBody.Text;

Console.WriteLine(getBodyText);
Console.WriteLine("Click any key to exit..");
Console.ReadKey();

driver.Quit();
}
}
34 changes: 34 additions & 0 deletions csharp/firefox/example.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

class Program
{
static void Main(string[] args)
{
FirefoxOptions options = new FirefoxOptions();

var proxy = new Proxy
{
Kind = ProxyKind.Manual,
IsAutoDetect = false,
HttpProxy = "gate.smartproxy.com:7000"
};
options.Proxy = proxy;

IWebDriver driver = new FirefoxDriver(options);
driver.Navigate().GoToUrl("http://ip.smartproxy.com/");
var getBody = driver.FindElement(By.TagName("body"));
var getBodyText = getBody.Text;

Console.WriteLine(getBodyText);
Console.WriteLine("Click any key to exit..");
Console.ReadKey();

driver.Quit();
}
}
97 changes: 97 additions & 0 deletions java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
## <img src="https://smartproxy.com/wp-content/themes/smartproxy/images/smartproxy-logo.svg" alt="" width="200" height="50">

### Disclaimer

Selenium is a browser automation tool. This particular repository only covers Selenium setup for Java based programming language.

To continue further development with this tool, make sure to read their [documentation](https://seleniumhq.github.io/selenium/docs/api/java/index.html) for Java.

*Unfortunately, Selenium itself does not support `username:password` authentication for `HTTP/HTTPs` proxies, thus you will need to have your IP whitelisted.*

You can do that by following guidlines listed [here](http://help.smartproxy.com/article/how-to-manage-whitelisted-ips/).

### Prerequisites

- [Java](https://www.java.com/en/)
- [Java SE Runtime Environment 8](https://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html)
- [Selenium Server 3.9.1](https://selenium-release.storage.googleapis.com/3.9/selenium-server-3.9.1.zip)
- [Selenium Server Standalone JAR](https://selenium-release.storage.googleapis.com/3.9/selenium-server-standalone-3.9.1.jar)

Optional:
- [Chrome WebDriver](https://sites.google.com/a/chromium.org/chromedriver/downloads)
- [Firefox WebDriver](https://github.com/mozilla/geckodriver/releases)

Note that you need to have at least one of the above drivers to continue your progress.

### Installation

This particular code was built with [Eclipse](https://www.eclipse.org/) which will be used to build and launch the application.

If you feel like using something else or executing the script with `javac` command, you may need to install [JAVA JRE](https://www.oracle.com/technetwork/java/javase/downloads/server-jre8-downloads-2133154.html).

Once you have all the prerequisites ready, create your project folder:

```
mkdir your_project
```
<img src="https://i.imgur.com/6US2PJs.png">

When project directory is setup, you can now download our example script for Selenium.

Make sure that you download the script accordingly to which WebDriver you want to use:

1. Open Terminal/Command Prompt window.
2. Navigate to the main directory of your project folder using `cd your_project`
3. Download one of the examples below.
4. You should now see your project folder populated with *example.java* file.

*Firefox*

```
curl https://raw.githubusercontent.com/Smartproxy/Smartproxy/master/selenium/java/firefox/example.java > example.java
```

<img src="https://i.imgur.com/nDiczWx.png">

*Chrome*

```
curl https://raw.githubusercontent.com/Smartproxy/Smartproxy/master/selenium/java/chrome/example.java > example.java
```

<img src="https://i.imgur.com/G3V8eEx.png">

### Configuration

To configure the proxy, simply change the following strings in the code:

```
String ProxyServer = "gate.smartproxy.com"; #Location you want to target
int ProxyPort = 7000; #Port for session
```

<img src="https://i.imgur.com/RfCa9xV.png">

### Testing

If everything is done correctly, after running the code, selected WebDriver will apear with a new IP from the proxy service:

<img src="https://i.imgur.com/EUbzHh4.png">

You will also get a printed output of the IP in the Console:

<img src="https://i.imgur.com/tBbOAlA.png">

## How to get started with Smartproxy?
<br><img src="https://smartproxy.com/wp-content/uploads/2019/02/order-smartproxy.png">
<br> 1. To utilize residential proxies you will require smartproxy account, register here -> https://dashboard.smartproxy.com
<br> 2. You will need an active subscription too. If you're interested in testing it out first - our plans Starter and above have 3 day money back policy -> https://smartproxy.com/pricing
<br> 3. Once you purchase it you will get access to whole pool, regardless of plan!
<br><br><center>Accepted payment methods:
<br><img src="https://smartproxy.com/wp-content/uploads/2018/09/payment-methods-smartproxy-residential-rotating-proxies.svg" alt="" width="250" height="50"></center>

## Contacts
Email - [email protected]
<br><a href="https://smartproxy.com">Live chat 24/7</a>
<br><a href="https://join.skype.com/invite/bZDHw4NZg2G9">Skype</a>
<br><a href="https://t.me/smartproxy_com">Telegram</a>
43 changes: 43 additions & 0 deletions java/chrome/example.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package chromeScripts;

import java.io.File;

import org.openqa.selenium.By;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;

public class Example {

public static void main(String[] args) {

String ProxyServer = "gate.smartproxy.com";
int ProxyPort = 7000;

String sHttpProxy = ProxyServer + ":" + ProxyPort;

Proxy proxy = new Proxy();

proxy.setHttpProxy(sHttpProxy);

ChromeDriverService service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("PATH TO WEBDRIVER"))
.usingAnyFreePort()
.build();
ChromeOptions options = new ChromeOptions();

options.setCapability("proxy", proxy);

options.merge(options);

WebDriver driver=new ChromeDriver(service, options);
driver.get("http://ip.smartproxy.com/");
WebElement body = driver.findElement(By.tagName("body"));
String bodyText = body.getText();
System.out.println(bodyText);
}

}
43 changes: 43 additions & 0 deletions java/firefox/example.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import java.io.File;

import org.openqa.selenium.By;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.GeckoDriverService;

public class Example {

public static void main(String[] args) {

String ProxyServer = "gate.smartproxy.com";
int ProxyPort = 7000;

String sHttpProxy = ProxyServer + ":" + ProxyPort;

Proxy proxy = new Proxy();

proxy.setHttpProxy(sHttpProxy);

GeckoDriverService service =new GeckoDriverService.Builder()
.usingDriverExecutable(new File("PATH TO WEBDRIVER"))
.usingAnyFreePort()
.usingAnyFreePort()
.build();
FirefoxOptions options = new FirefoxOptions();

options.setCapability("proxy", proxy);

options.merge(options);

WebDriver driver=new FirefoxDriver(service, options);
driver.get("http://ip.smartproxy.com/");
WebElement body = driver.findElement(By.tagName("body"));
String bodyText = body.getText();
System.out.println(bodyText);

}

}
Loading

0 comments on commit 2788c34

Please sign in to comment.