gpt4 book ai didi

Java selenium getPageSource 不工作

转载 作者:行者123 更新时间:2023-11-29 06:57:47 24 4
gpt4 key购买 nike

我需要程序中给出的url的来源。但是程序只返回一些 json 数据而不是整个页面源。有什么问题??

public class selenium
{
public static void main(String[] args)
{
selenium.loadPage("http://photos.filmibeat.com/celebs/kajal-aggarwal/photos-c14-e13421-p592995.html");
}
public static void loadPage(String url)
{

WebDriver driver = new FirefoxDriver();

driver.get(url);

String html = driver.getPageSource();

System.out.println(html);

driver.quit();

}
}

最佳答案

我只是在@alecxe 的回答上添加更多信息 alecxe 提供的解决方案运行良好

eclipse的控制台输出大小默认只有80000个字符

enter image description here

Window > Preferences,转到Run/Debug > Console 部分> 然后禁用limit console option

或者将数据写入文件

    File file = new File("path/filename.txt");
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();

希望对你有帮助

关于Java selenium getPageSource 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31307541/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com