HTMLコードは次のようになります。
<a href="" onclick="MSV_hybrid_lab_open("construct.asp?pid=DEMO&mode=EnterLab&regn=10887898&pcd=12367&type=L&corpaccd=DEMOLLAB");return false;"><font class="snormal">Planning</font></a>
onclickからテキストを取得する必要があります。pid = DEMOが必要です
誰かが私を助けることができますか?私はJava + Seleniumを使用しています。ありがとう
テキストでリンクを検索し、その属性onclick
を取得してから、解析して次の情報を取得しますpid
。
// Initialize driver, navigate to the page
WebDriver driver = new FirefoxDriver(); // or other browser
// ... (navigate to the page, etc.)
// Find the link by partial link text
WebElement link = driver.findElement(By.partialLinkText("Planning"));
// Get the attribute (entire value)
String onclick = link.getAttribute("onclick");
// From here you can use any of the string parsing to get what you want.
// Here's the simple regex way:
String pid = "";
Pattern pattern = Pattern.compile("pid=([^\\&]*)&"); //search for anything between 'pid=' and '&'
Matcher matcher = pattern.matcher(mydata);
if (matcher.find())
{
pid = matcher.group(1); // should be only one
}
System.out.println(pid);
印刷します
DEMO
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加