在java代码中显示异常(Selenium+;Jsoup)

在java代码中显示异常(Selenium+;Jsoup),java,exception,selenium,jsoup,Java,Exception,Selenium,Jsoup,我正在做一个项目。在这方面,我必须得到HTML页面的源代码。为此,我使用Selenium调用firefox驱动程序,并以字符串形式存储页面源代码,然后使用Jsoup 我的代码在单个url上运行良好。但是当我把我的代码放在测试中,它必须一个接一个地获取URL的数量,然后在最后它抛出一个异常,我的项目失败了。请查看异常并告诉我发生这种情况的原因,并给我一些解决方案来克服此异常 我的selenium代码如下所示, private static FirefoxProfile createFirefoxP

我正在做一个项目。在这方面,我必须得到HTML页面的源代码。为此,我使用
Selenium
调用firefox驱动程序,并以字符串形式存储页面源代码,然后使用
Jsoup

我的代码在单个
url
上运行良好。但是当我把我的代码放在测试中,它必须一个接一个地获取URL的数量,然后在最后它抛出一个异常,我的项目失败了。请查看异常并告诉我发生这种情况的原因,并给我一些解决方案来克服此异常

我的selenium代码如下所示,

private static FirefoxProfile createFirefoxProfile() {
    File profileDir = new File("/tmp/firefox-profile-dir");
    if (profileDir.exists()) {
        return new FirefoxProfile(profileDir);
    }
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    File dir = firefoxProfile.layoutOnDisk();
    try {
        profileDir.mkdirs();
        FileUtils.copyDirectory(dir, profileDir);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return firefoxProfile;
}
[WARNING] 
    java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
        at java.lang.Thread.run(Thread.java:662)
    Caused by: org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files (x86)\Mozilla Firefox\firefox.exe) on port 7056; process output follows: 
    null
    Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
    System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_43'
    Driver info: driver.version: FirefoxDriver
        at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:122)
        at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:188)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:183)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:179)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:96)
        at XXX.YYY.ZZZ.Template_Matching.Scroll_down.processing(Scroll_down.java:334)
        at XXX.YYY.ZZZ.Template_Matching.Scroll_down.main(Scroll_down.java:472)
        ... 6 more
    Caused by: org.openqa.selenium.firefox.UnableToCreateProfileException: java.io.IOException: There is not enough space on the disk
    Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
    System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_43'
    Driver info: driver.version: FirefoxDriver
        at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:453)
        at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:77)
        ... 14 more
    Caused by: java.io.IOException: There is not enough space on the disk
        at java.io.FileOutputStream.writeBytes(Native Method)
        at java.io.FileOutputStream.write(FileOutputStream.java:282)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:109)
        at org.openqa.selenium.io.Zip.unzipFile(Zip.java:171)
        at org.openqa.selenium.io.Zip.unzip(Zip.java:152)
        at org.openqa.selenium.io.FileHandler.unzip(FileHandler.java:54)
        at org.openqa.selenium.firefox.internal.FileExtension.obtainRootDirectory(FileExtension.java:81)
        at org.openqa.selenium.firefox.internal.FileExtension.writeTo(FileExtension.java:58)
        at org.openqa.selenium.firefox.internal.ClasspathExtension.writeTo(ClasspathExtension.java:63)
        at org.openqa.selenium.firefox.FirefoxProfile.installExtensions(FirefoxProfile.java:469)
        at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:447)
        ... 15 more
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 20:49:03.625s
    [INFO] Finished at: Thu Apr 18 10:47:12 IST 2013
    [INFO] Final Memory: 12M/163M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project Template_Matching: An exception occured while executing the Java class. null: InvocationTargetException: Failed to connect to binary FirefoxBinary(C:\Program Files (x86)\Mozilla Firefox\firefox.exe) on port 7056; process output follows:
    [ERROR] null
    [ERROR] Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
    [ERROR] System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_43'
    [ERROR] Driver info: driver.version: FirefoxDriver: java.io.IOException: There is not enough space on the disk
    [ERROR] Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
    [ERROR] System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_43'
    [ERROR] Driver info: driver.version: FirefoxDriver
    [ERROR] -> [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
//下面是主函数中的代码(url1和url2是两个URL)

WebDriver driver = new FirefoxDriver(createFirefoxProfile());
driver.get(url1);
String hml1 = driver.getPageSource();
driver.get(url2);
String hml2 = driver.getPageSource();
driver.close();
例外情况

private static FirefoxProfile createFirefoxProfile() {
    File profileDir = new File("/tmp/firefox-profile-dir");
    if (profileDir.exists()) {
        return new FirefoxProfile(profileDir);
    }
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    File dir = firefoxProfile.layoutOnDisk();
    try {
        profileDir.mkdirs();
        FileUtils.copyDirectory(dir, profileDir);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return firefoxProfile;
}
[WARNING] 
    java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
        at java.lang.Thread.run(Thread.java:662)
    Caused by: org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files (x86)\Mozilla Firefox\firefox.exe) on port 7056; process output follows: 
    null
    Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
    System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_43'
    Driver info: driver.version: FirefoxDriver
        at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:122)
        at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:188)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:183)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:179)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:96)
        at XXX.YYY.ZZZ.Template_Matching.Scroll_down.processing(Scroll_down.java:334)
        at XXX.YYY.ZZZ.Template_Matching.Scroll_down.main(Scroll_down.java:472)
        ... 6 more
    Caused by: org.openqa.selenium.firefox.UnableToCreateProfileException: java.io.IOException: There is not enough space on the disk
    Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
    System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_43'
    Driver info: driver.version: FirefoxDriver
        at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:453)
        at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:77)
        ... 14 more
    Caused by: java.io.IOException: There is not enough space on the disk
        at java.io.FileOutputStream.writeBytes(Native Method)
        at java.io.FileOutputStream.write(FileOutputStream.java:282)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
        at java.io.BufferedOutputStream.write(BufferedOutputStream.java:109)
        at org.openqa.selenium.io.Zip.unzipFile(Zip.java:171)
        at org.openqa.selenium.io.Zip.unzip(Zip.java:152)
        at org.openqa.selenium.io.FileHandler.unzip(FileHandler.java:54)
        at org.openqa.selenium.firefox.internal.FileExtension.obtainRootDirectory(FileExtension.java:81)
        at org.openqa.selenium.firefox.internal.FileExtension.writeTo(FileExtension.java:58)
        at org.openqa.selenium.firefox.internal.ClasspathExtension.writeTo(ClasspathExtension.java:63)
        at org.openqa.selenium.firefox.FirefoxProfile.installExtensions(FirefoxProfile.java:469)
        at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:447)
        ... 15 more
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 20:49:03.625s
    [INFO] Finished at: Thu Apr 18 10:47:12 IST 2013
    [INFO] Final Memory: 12M/163M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project Template_Matching: An exception occured while executing the Java class. null: InvocationTargetException: Failed to connect to binary FirefoxBinary(C:\Program Files (x86)\Mozilla Firefox\firefox.exe) on port 7056; process output follows:
    [ERROR] null
    [ERROR] Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
    [ERROR] System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_43'
    [ERROR] Driver info: driver.version: FirefoxDriver: java.io.IOException: There is not enough space on the disk
    [ERROR] Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
    [ERROR] System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_43'
    [ERROR] Driver info: driver.version: FirefoxDriver
    [ERROR] -> [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[警告]
java.lang.reflect.InvocationTargetException
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)中
位于java.lang.reflect.Method.invoke(Method.java:597)
位于org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
运行(Thread.java:662)
原因:org.openqa.selenium.WebDriverException:无法连接到端口7056上的二进制FirefoxBinary(C:\Program Files(x86)\Mozilla Firefox\Firefox.exe);过程输出如下:
无效的
构建信息:版本:“2.31.0”,修订版:“1bd294d185a80fa4206dfeab80ba773c04ac33c0”,时间:“2013-02-27 13:51:26”
系统信息:os.name:'windows7',os.arch:'amd64',os.version:'6.1',java.version:'1.6.043'
驱动程序信息:Driver.version:FirefoxDriver
位于org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:122)
位于org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244)
位于org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:110)
位于org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:188)
位于org.openqa.selenium.firefox.FirefoxDriver(FirefoxDriver.java:183)
位于org.openqa.selenium.firefox.FirefoxDriver(FirefoxDriver.java:179)
位于org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:96)
在XXX.YYY.ZZZ.Template_Matching.Scroll_down.processing(Scroll_down.java:334)
在XXX.YYY.ZZZ.Template_Matching.Scroll_down.main(Scroll_down.java:472)
... 还有6个
原因:org.openqa.selenium.firefox.UnableToCreateProfileException:java.io.IOException:磁盘空间不足
构建信息:版本:“2.31.0”,修订版:“1bd294d185a80fa4206dfeab80ba773c04ac33c0”,时间:“2013-02-27 13:51:26”
系统信息:os.name:'windows7',os.arch:'amd64',os.version:'6.1',java.version:'1.6.043'
驱动程序信息:Driver.version:FirefoxDriver
位于org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:453)
位于org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:77)
... 14多
原因:java.io.IOException:磁盘空间不足
位于java.io.FileOutputStream.writeBytes(本机方法)
在java.io.FileOutputStream.write(FileOutputStream.java:282)处
位于java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
在java.io.BufferedOutputStream.write处(BufferedOutputStream.java:109)
位于org.openqa.selenium.io.Zip.unzipFile(Zip.java:171)
位于org.openqa.selenium.io.Zip.unzip(Zip.java:152)
位于org.openqa.selenium.io.FileHandler.unzip(FileHandler.java:54)
位于org.openqa.selenium.firefox.internal.FileExtension.obtainRootDirectory(FileExtension.java:81)
位于org.openqa.selenium.firefox.internal.FileExtension.writeTo(FileExtension.java:58)
位于org.openqa.selenium.firefox.internal.ClasspathExtension.writeTo(ClasspathExtension.java:63)
位于org.openqa.selenium.firefox.FirefoxProfile.installExtensions(FirefoxProfile.java:469)
位于org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:447)
... 还有15个
[信息]------------------------------------------------------------------------
[信息]生成失败
[信息]------------------------------------------------------------------------
[信息]总时间:20:49:03.625s
[信息]完成时间:2013年4月18日星期四10:47:12
[信息]最终内存:12M/163M
[信息]------------------------------------------------------------------------
[错误]无法在项目模板上执行goal org.codehaus.mojo:exec maven plugin:1.2.1:java(默认cli):匹配:执行java类时发生异常。null:InvocationTargetException:无法连接到端口7056上的二进制FirefoxBinary(C:\Program Files(x86)\Mozilla Firefox\Firefox.exe);过程输出如下:
[错误]空
[错误]生成信息:版本:“2.31.0”,修订版:“1bd294d185a80fa4206dfeab80ba773c04ac33c0”,时间:“2013-02-27 13:51:26”
[错误]系统信息:os.name:'Windows 7',os.arch:'amd64',os.version:'6.1',java.version:'1.6.0_43'
[错误]驱动程序信息:Driver.version:FirefoxDriver:java.io.IOException:磁盘空间不足
[错误]生成信息:版本:“2.31.0”,修订版:“1bd294d185a80fa4206dfeab80ba773c04ac33c0”,时间:“2013-02-27 13:51:26”
[错误]系统信息:os.name:'Windows 7',os.arch:'amd64',os.version:'6.1',java.version:'1.6.0_43'
[错误]驱动程序信息:驱动程序。版本:FirefoxDriver
[错误]->[帮助1]
[错误]
[错误]要查看错误的完整堆栈跟踪,请使用-e开关重新运行Maven。
[错误]使用-X开关重新运行Maven以启用完整调试日志记录。
[错误]
[错误]有关错误和可能的解决方案的更多信息,请阅读以下文章:
[错误][帮助1]http://cwiki.apache.org/confluen