我正在尝试与Selenium进行刮擦练习,但我遇到了一些问题。
这是我的代码:
package ScraperPakage;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import java.util.List;
public class ScraperClass {
public static void main(String[] args) {
//Create a new instance of Firefox Browser
System.setProperty("webdriver.gecko.driver", "C:\\Users\\xxxx\\Selenium\\geckodriver-v0.10.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
//Open the URL in firefox browser
driver.get("http://www.budgettravel.ie");
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
List<WebElement> titles = driver.findElements(By.cssSelector("div.travelOfferList"));
for (int j = 0; j < titles.size(); j++) {
System.out.println( "\t - " + titles.get(j).getText() ) ;
}
driver.quit();
}
}
代码返回商品假期列表,但以错误列表结束,我不知道如何解决。
这是输出:
JavaScript warning: resource://cck2/CCK2.jsm, line 998: unreachable code after return statement
JavaScript warning: resource://cck2/Preferences.jsm, line 556: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create
1472551987508 Marionette INFO Listening on port 62410
JavaScript warning: https://normandy.cdn.mozilla.net/static/bundles/selfrepair-068962304d04a2173e88.94ed0f93a4f3.js, line 11002: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create
Page title is: Cheap Holidays 2016/ 2017, Cheap Sun Holidays from Dublin, All Inclusive Sun Package Holidays from Ireland, Cheap Last Minute Holidays & Deals, All Inclusive Late Holiday Deals - Budget Travel
- Last Minute Deals
Where
When
Nights
From
Costa Blanca
21 Sep
7
€185pp
[ ... REST OF THE LIST ...]
Costa Dorada
22 Oct
7
€146pp
[Child 14212] WARNING: pipe error: 232: file c:/builds/moz2_slave/m-rel-w32-00000000000000000000/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 487
[Child 14212] ###!!! ABORT: Aborting on channel error.: file c:/builds/moz2_slave/m-rel-w32-00000000000000000000/build/src/ipc/glue/MessageChannel.cpp, line 2027
[NPAPI 13576] ###!!! ABORT: Aborting on channel error.: file c:/builds/moz2_slave/m-rel-w32-00000000000000000000/build/src/ipc/glue/MessageChannel.cpp, line 2027
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: 'unknown', revision: '2aa21c1', time: '2016-08-02 14:59:43 -0700'
System info: host: 'xxxx', ip: 'xxxx', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_101'
Driver info: driver.version: RemoteWebDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, appBuildId=20160623154057, version=, platform=XP, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, browserVersion=47.0.1, platformVersion=6.1, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=Firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=Windows_NT, device=desktop}]
Session ID: 3ad95378-01d1-4c6c-a3ce-24f992fb5289
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:670)
[... OTHER LINES LIKE THE LINE JUST ABOVE ...]
另外,有两个窗口打开'用于Firefox的插件容器已停止工作'
Problem signature:
Problem Event Name: APPCRASH
Application Name: plugin-container.exe
Application Version: 47.0.1.6018
Application Timestamp: 576c9637
Fault Module Name: mozglue.dll
Fault Module Version: 47.0.1.6018
Fault Module Timestamp: 576c85ba
Exception Code: 80000003
Exception Offset: 0000f02b
OS Version: 6.1.7601.2.1.0.256.4
Locale ID: 6153
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
任何想法,为什么我在最后得到错误,窗口在最后打开。
由于