问题描述
问题是如果用户输入 Instagram URL,如何从 Instagram 个人资料中读取文本.我尝试使用 java.net.URL,但得到的只是大量的 HTML 文本.我对使用网页几乎一无所知,因此我正在寻求有关如何从个人资料中获取文本(个人简介、帖子标题、评论)的帮助.
The question is how to read text from an Instagram profile if a user inputs an Instagram URL. I tried using java.net.URL and all I get is a big load of HTML text. I know little to nothing about working with web pages, so I am seeking some help with how I would get text from the profile (bio, post captions, comments).
谢谢!
推荐答案
您可以使用 jsoup (https://jsoup.org/) 从 html 内容中提取特定标签.
You can use jsoup (https://jsoup.org/) to extract the specific tag from html content.
这是从 HTML 正文中提取 h1 标记内容的示例.
Here is an example to extract h1 tag content from the body of the HTML.
// Parse HTML String using JSoup library
String HTMLSTring = "<!DOCTYPE html>"
+ "<html>"
+ "<head>"
+ "<title>JSoup Example</title>"
+ "</head>"
+ "<body>"
+ "<table><tr><td>
<h1>HelloWorld</h1></tr>"
+ "</table>"
+ "</body>"
+ "</html>";
Document html = Jsoup.parse(HTMLSTring);
String title = html.title();
String h1 = html.body().getElementsByTag("h1").text();
您可以从以下博客文章中找到更多示例https://javarevisited.blogspot.com/2014/09/how-to-parse-html-file-in-java-jsoup-example.html
You can find a few more examples from the below blog posthttps://javarevisited.blogspot.com/2014/09/how-to-parse-html-file-in-java-jsoup-example.html
希望对您有所帮助.
这篇关于从 Instagram 个人资料中读取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!