import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class JSoupExampleForJDPA {
public static void main(String[] args) throws IOException {
org.jsoup.nodes.Document document;
String url = "http://scripting.jdpoweronline.com/mrIWeb/mrIWeb.dll?I.Project=T1_QTYPE&i.test=1";
WebDriver driver = new FirefoxDriver();
driver.get(url);
for (int i = 0; i <= 3; i++) {
String currentUrl = driver.getCurrentUrl();
if (i == 0) {
document =Jsoup.connect(url).ignoreContentType(true)
.timeout(60 * 1000)
.userAgent("Mozilla")
.cookie("auth", "token")
.timeout(3000)
.get();
} else {
document = Jsoup.connect(currentUrl).ignoreContentType(true)
.timeout(60 * 1000)
.userAgent("Mozilla")
.cookie("auth1", "token1")
.timeout(3000)
.get();
}
Elements elements = document.select("a");
System.out.println("******************* currentUrl " + currentUrl + "*******************");
if (!elements.isEmpty()) {
for (Element elementsIterator : elements) {
String href = elementsIterator.attr("href");
System.out.println("a[href=" + '"' + href + '"' + "]");
}
}
if (i == 0) {
driver.findElement(By.cssSelector(".mrNext")).click();
} else if (i == 1) {
driver.findElement(By.cssSelector("#_Q0_C0")).click();
driver.findElement(By.cssSelector(".mrNext")).click();
}
else if (i == 2) {
driver.findElement(By.cssSelector("#_Q1_C0")).click();
driver.findElement(By.cssSelector(".mrNext")).click();
}
}
}
}
This is my code. Here i am opening URL (as given) with driver.get() method of Selenium.
Also i wanted to get all HREF tags present on current page. So I am doing this using Jsoup.connect() method. In for loops, navigating to next page. Problem is that i am getting HREF tags of 1st page only not of next pages. URL not working when i copy paste in another tab.
我遇到了以下异常
Exception in thread "main" org.jsoup.HttpStatusException: HTTP error fetching URL. Status=400, URL=http://scripting.jdpoweronline.com/mrIWeb/mrIWeb.dll#4
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:449)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:424)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:178)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:167)
at publicc.JSoupExampleForJDPA.main(JSoupExampleForJDPA.java:41)
答案 0 :(得分:0)
此网址 - &gt; http://scripting.jdpoweronline.com/mrIWeb/mrIWeb.dll#4
返回400错误。单击它并检查服务器响应。试图去寻找
哪个页面包含此网址。您可以避免解析以dll#<number>
结尾的网址。