FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
selenium-proxy-integration-java/src/main/java/ProxyDemo.java at main · oxylabs/selenium-proxy-integration-java · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
oxylabs
/
selenium-proxy-integration-java
Public
Notifications
You must be signed in to change notification settings
Fork
3
Star
6
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
selenium-proxy-integration-java
/
src
/
main
/
java
/
ProxyDemo.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
73 lines (58 loc) · 2.44 KB
Breadcrumbs
selenium-proxy-integration-java
/
src
/
main
/
java
/
ProxyDemo.java
Copy path
File metadata and controls
73 lines (58 loc) · 2.44 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import
io
.
github
.
bonigarcia
.
wdm
.
WebDriverManager
;
import
net
.
lightbody
.
bmp
.
BrowserMobProxyServer
;
import
org
.
openqa
.
selenium
.
By
;
import
org
.
openqa
.
selenium
.
NoSuchElementException
;
import
org
.
openqa
.
selenium
.
WebDriver
;
import
org
.
openqa
.
selenium
.
WebElement
;
public
class
ProxyDemo
{
public
static
void
main
(
String
[]
args
) {
randomIPDemo
();
countrySpecificIPDemo
(
"DE"
);
}
private
static
void
countrySpecificIPDemo
(
String
countryCode
) {
WebDriverManager
.
chromedriver
().
setup
();
BrowserMobProxyServer
proxy
=
ProxyHelper
.
getProxy
(
ProxySetup
.
ENDPOINT
,
ProxySetup
.
USERNAME
,
ProxySetup
.
PASSWORD
,
countryCode
);
// Returns random proxy in that country
WebDriver
driver
=
ProxyHelper
.
getDriver
(
proxy
,
true
);
try
{
// Selenium Code Here
driver
.
get
(
"https://ip.oxylabs.io/"
);
// Parse the response and get IP from <pre>
try
{
WebElement
preElement
=
driver
.
findElement
(
By
.
cssSelector
(
"pre"
));
System
.
out
.
println
(
"Your IP is "
+
preElement
.
getText
());
}
catch
(
NoSuchElementException
e
) {
System
.
out
.
println
(
"IP Not Found.
\n
"
+
driver
.
getPageSource
());
}
}
finally
{
driver
.
quit
();
// Quit the driver
proxy
.
stop
();
// Quit local JVM proxy
}
}
private
static
void
randomIPDemo
() {
WebDriverManager
.
chromedriver
().
setup
();
BrowserMobProxyServer
proxy
=
ProxyHelper
.
getProxy
(
ProxySetup
.
ENDPOINT
,
ProxySetup
.
USERNAME
,
ProxySetup
.
PASSWORD
,
null
);
// Return random proxy in any country
WebDriver
driver
=
ProxyHelper
.
getDriver
(
proxy
,
true
);
try
{
// Selenium Code Here
driver
.
get
(
"https://ip.oxylabs.io/"
);
// Parse the response and get IP from <pre>
try
{
WebElement
preElement
=
driver
.
findElement
(
By
.
cssSelector
(
"pre"
));
System
.
out
.
println
(
"Your IP is "
+
preElement
.
getText
());
}
catch
(
NoSuchElementException
e
) {
System
.
out
.
println
(
"IP Not Found.
\n
"
+
driver
.
getPageSource
());
}
}
finally
{
driver
.
quit
();
// Quit the driver
proxy
.
stop
();
// Quit local JVM proxy
}
}
}
Back
|
FazBrowse Home
|
New Git URL