如何从Selenium Webdriver中的以下URL获取syskey_request_token: https://gimain03.uat.income.com.sg/insurance/mainMenu.do?syskey_request_to ken = 2b7c09eda6d7acf3b95b6745152cf521
答案 0 :(得分:0)
您可以使用正则表达式来处理它,例如:
import re
currentPageUrl = driver.current_url
syskey_request_token = re.findall('syskey_request_token=.*', currentPageUrl)[0]
答案 1 :(得分:0)
再次引起我一些误解,这是Java解决方案:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class main {
public static void main(String[] args) {
openChrome();
}
/**
* open chrome driver
*/
public static void openChrome() {
// path of driver
System.setProperty("webdriver.chrome.driver", "driver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
// Typing your URL below
driver.get("xxx://xxx.xxx.xxx");
String currentURL = driver.getCurrentUrl();
// Using regex to find key 'syskey_request_token='
Pattern pattern = Pattern.compile("syskey_request_token=(.*)");
Matcher matcher = pattern.matcher(currentURL);
matcher.find();
System.out.print(currentURL+"\n");
System.out.print(matcher.group(1)+"\n");
}
}