selenium 获取网页所有链接

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class Catch {
 public static void main(String[] args) {
  WebDriver driver = driver = new InternetExplorerDriver();
  driver.get("http://www.java3z.com/cwbwebhome/index1.jsp");
  List list = driver.findElements(By.tagName("a"));
  for (int i = 0; i < list.size(); i++) {
   if (list.get(i).getText().toLowerCase().contains("java")) {

    System.out.println(list.get(i).getText() + "      "
      + list.get(i).getAttribute("href"));

   }

  }
 }
}

你可能感兴趣的:(selenium 获取网页所有链接)