我正在尝试获取网站上文本字段的值...
除了从 uri 读取它还有其他方法吗? 例如像
getContent().getvar("name");
最佳答案
您需要使用像 jsoup
( here ) 这样的库来连接到站点 (url) 并获取 DOM 格式的数据。下面是一个示例代码片段:
Document doc = Jsoup.connect("http://google.com").get();
String title = doc.title();
System.out.println("title : " + title);
Elements links = doc.select("a[href]");
您可以使用select
之类的方法来获取所需的元素,例如:
Element head= doc.select("div.head").first();
Here是 Document 类的 javadoc 和 here是一些例子。
如果您有网站的 HTML 代码,您可以使用 jsoup
读取它并将其转换为 Document
对象。不幸的是,没有实际连接(通过 uri)的情况下直接方式读取网站/页面的内容。
关于java - Sun 的 HTTP-Server 直接读取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42101887/