如何从网页中提取源html?

2024-05-07 05:16:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图提取这个页面的html源文件,http://www.fxstreet.com/rates-charts/currency-rates/

我想要当我把chrome页面保存为.html文件时看到的内容。在

我尝试在java中使用bufferedreader,然后使用jsoup。我也试着用python来做,但是我一直得到以下消息:

“此网站需要启用JavaScript和Cookies。请更改浏览器设置或升级浏览器。“

最终目标是提取主表中的值。在


Tags: 文件comhttp内容htmlwww浏览器页面
2条回答

使用Jsoup可以很容易地提取主表

下面是一个方法,它将从页面的主表中获取所有内容

public void parse(){
        try{

        Document doc = Jsoup.connect("http://www.fxstreet.com/rates-charts/currency-rates/").get();
        Element content = doc.getElementById("ddlPairsChoose");
        Elements table = doc.getElementsByClass("applet-content");      

        System.out.print(table);

        }

        catch(Exception e){

            System.out.print("error  > " + e);
        }       
    }

它打印出页面上的表格

尝试使用HtmlUnit并设置setJavascriptEnabled(true)

另请看:thisthis

JSoup不是执行Javascript的无头浏览器,因此必须选择其他库来获取页面,然后才能使用JSoup解析它。在

相关问题 更多 >