java - 使用Jsoup提取div中的表格数据

标签 java html web-scraping jsoup

我试过各种方法获取div标签的表格数据,但都没有成功。当我查看源代码时,我能够看到表的值。但是当我运行以提取值时,甚至无法识别该表。该表位于此 div 标记内。

<div xmlns:saxon="http://saxon.sf.net/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:fo="http://www.w3.org/1999/XSL/Format">

我试过的方法。

Element table = doc.select("table").first();
Elements rows = table.select("tr");
for (int i = 1; i < rows.size(); i++) { 
    Element row = rows.get(i);
    Elements tds = row.select("td");
    System.out.println(tds.get(0).text() + ":" + tds.get(1).text());
}

我试过按类、标签等获取表格。这与 div 标签有什么关系吗?

最佳答案

解决方案由Duffydake提供:

You can do this in almost any language. There are two solutions, use something like "phantomjs" to get the "real" page (with javascript interpreted) or use this URL.

OP 回复:

Thanks.. I need to check on phantomjs.. But with the other url I am able to extract values. Just need to format it now.

关于java - 使用Jsoup提取div中的表格数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31067875/

相关文章:

java - 是否有 MSDN 成员(member)资格可以获得的 Java Profiler?

java - Apache Spark和Scala中数据集的移动平均值

javascript - 使用 Javascript 的简单搜索功能

java - 通过命令行运行 Junit 测试

java - 以这种格式从字符串中解析日期 : dd/MM/yyyy [to dd/MM/yyyy]

html - 相同ID的div重叠

php - HTML 到纯文本(用于电子邮件)

javascript - 尝试过 Python BeautifulSoup 和 Phantom JS : STILL can't scrape websites

html - 如何使用 beautifulsoup 获取位于另一个标签内的 span 标签内的文本?

Python CrawlSpider