国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

目次
Jsoup Overview
All Jsoup Examples
Example #4
Conclusion – Jsoup Example

Jsoup の例

Sep 04, 2024 pm 04:55 PM
html html5 HTML Tutorial HTML Properties HTML tags

Basically, Java provides different types of libraries to the user, in which jsoup maven is one of the libraries that are provided by Java. Jsoup normally is used while we need to work with the real-time HTML pages. Jsoup provides the different types of API to fetch the different URLs and manipulates them with the help of HTML5 DOM and a selector of CSS as per requirement. By using jsoup we perform a different operation or we can say that we can write the different programs for getting the title of a web page, get a number of links from a specific web page, get a number of images from the specified web pages and we can get the metadata of URL and HTML documents.

Jsoup Overview

Jsoup is an open-source Java library utilized essentially for separating information from HTML. It additionally permits you to control and yield HTML. It has a consistent improvement line, extraordinary documentation, and a familiar and adaptable API. Jsoup can likewise be utilized to parse and fabricate XML.

Jsoup loads the page HTML and constructs the related DOM tree. This tree works the same way as the DOM in a program, offering techniques like jQuery and vanilla JavaScript to choose the cross, control text/HTML/characteristics and add/eliminate components.
Different components of Jsoup are listed below as follows.

  • Stacking: Bringing and parsing the HTML into a Document.
  • Separating: Choosing the ideal information into Elements and navigating it.
  • Removing: Getting properties, text, and HTML of hubs.
  • Changing: Adding/altering/eliminating hubs and altering their traits.

All Jsoup Examples

Now let’s see all the examples jsoup one by one as follows.

Example #1

package demo;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class jsoup {
public static void main(String[] args) {
String html_code = "<html><head><title>Welcome</title></head>"
+ "<body><p>This is jsoup program</p></body></html>";
Document docu = Jsoup.parse(html_code);
System.out.println(docu.title());
Elements para = docu.getElementsByTag("p");
for (Element paragraph : para) {
System.out.println(paragraph.text());
}
}
}

Explanation

This is a simple program of Jsoup where we try to fetch the content of web pages, in the above example we write the string with HTML code and we try to fetch that string by using Jsoup library as shown in the above code. The end result of the above program we illustrated by using the following screenshot as follows.

Jsoup の例

Now let’s see the second example of Jsoup as follows.

Example #2

package com.sample;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
public class jsample {
public static void main(String[] args) {
Document docu;
try {
// required protocol that is http
docu = Jsoup.connect("http://google.com").get();
// title of page
String title_page = docu.title();
System.out.println("title : " + title_page);
// links
Elements links_web = docu.select("a[href]");
for (Element link : links_web) {
// href attribute
System.out.println("\n web_link : " + link.attr("href"));
System.out.println("web_text : " + link.text());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

Explanation

By using the above code we try to find out the all hyperlinks of google.com. Here we first import the required packages and library as shown. After we write the code for HTTP protocol and how we can get the all hyperlinks for google.com as shown. The final output of the above program we illustrated by using the following screenshot as follows.

Jsoup の例

Now let’s see examples of images as follows.

Example #3

package demo;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
public class jsample {
public static void main(String[] args) {
Document docu;
try {
docu = Jsoup.connect("http://google.com").get();
Elements web_images = docu.select("img[src~=(?i)\\.(png|jpe?g|gif)]");
for (Element image : web_images) {
System.out.println("\nsrc : " + image.attr("src"));
System.out.println("Img_height : " + image.attr("height"));
System.out.println("Img_width : " + image.attr("width"));
System.out.println("Img_alt : " + image.attr("alt"));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

Explanation

By using the above example, we try to fetch all sources of images, here we try to fetch the images of google.com as shown in the above code. After that, we write the code to fetch the height, width as shown. The final output of the above program we illustrated by using the following screenshot as follows.

Jsoup の例

Now let’s see the example of metadata as follows.

package demo;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class jsample {
public static void main(String[] args) {
StringBuffer html_code = new StringBuffer();
html_code.append("<!DOCTYPE html>");
html_code.append("<html lang=\"en\">");
html_code.append("<head>");
html_code.append("<meta charset=\"UTF-8\" />");
html_code.append("<title>Hollywood Life</title>");
html_code.append("<meta name=\"description\" content=\"New trends in entertainment news\" />");
html_code.append("<meta name=\"keywords\" content=\"Cricket News, Bollywood News, Football News\" />");
html_code.append("</head>");
html_code.append("<body>");
html_code.append("<div id='color'>Blue color is here</div> />");
html_code.append("</body>");
html_code.append("</html>");
Document docu = Jsoup.parse(html_code.toString());
//get a description of metadata content
String des = docu.select("meta[name=description]").get(0).attr("content");
System.out.println("Meta description : " + des);
//get keyword of metadata content
String keyw = docu.select("meta[name=keywords]").first().attr("content");
System.out.println("Meta keyword : " + keyw);
String color_A = docu.getElementById("color").text();
String color_B = docu.select("div#color").get(0).text();
System.out.println(color_A);
System.out.println(color_B);
}
}

Explanation

By using the above code we try to implement the metadata in jsoup, here we write the HTML body and metadata and push by using the append function as shown. After that, we write the code for the metadata description and keyword of metadata. The final output of the above program we illustrated by using the following screenshot as follows.

Jsoup の例

Now let’s see how we can get icons as follows.

Example #4

package demo;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
public class jsample {
public static void main(String[] args) {
StringBuffer html_code = new StringBuffer();
html_code.append("<html lang=\"en\">");
html_code.append("<head>");
html_code.append("<link rel=\"icon\" href=\"http://specifiedurl.com/img.ico\" />");
html_code.append("</head>");
html_code.append("<body>");
html_code.append("something");
html_code.append("</body>");
html_code.append("</html>");
Document docu = Jsoup.parse(html_code.toString());
String fav = "";
Element ele = docu.head().select("link[href~=.*\\.(ico|png)]").first();
if(ele==null){
ele = docu.head().select("meta[itemprop=image]").first();
if(ele!=null){
fav = ele.attr("content");
}
}else{
fav = ele.attr("href");
}
System.out.println(fav);
}
}

Explanation

By using the above example we try to implement the get an icon in Jsoup, here we need to specify the URL of the website that we want. After that, we also need to mention the link tag of HTML as shown. The final output of the above program we illustrated by using the following screenshot as follows.

Jsoup の例

Conclusion – Jsoup Example

We hope from this article you learn more about the Jsoup example. From the above article, we have taken in the essential idea of the jsoup example. and we also see the representation and example of Jsoup examples. From this article, we learned how and when we use the Jsoup example.

以上がJsoup の例の詳細(xì)內(nèi)容です。詳細(xì)については、PHP 中國(guó)語(yǔ) Web サイトの他の関連記事を參照してください。

このウェブサイトの聲明
この記事の內(nèi)容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰屬します。このサイトは、それに相當(dāng)する法的責(zé)任を負(fù)いません。盜作または侵害の疑いのあるコンテンツを見つけた場(chǎng)合は、admin@php.cn までご連絡(luò)ください。

ホットAIツール

Undress AI Tool

Undress AI Tool

脫衣畫像を無(wú)料で

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード寫真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

寫真から衣服を削除するオンライン AI ツール。

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無(wú)料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡(jiǎn)単に交換できます。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無(wú)料のコードエディター

SublimeText3 中國(guó)語(yǔ)版

SublimeText3 中國(guó)語(yǔ)版

中國(guó)語(yǔ)版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強(qiáng)力な PHP 統(tǒng)合開発環(huán)境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

なぜ私の畫像がHTMLに表示されないのですか? なぜ私の畫像がHTMLに表示されないのですか? Jul 28, 2025 am 02:08 AM

表示されていない畫像は、通常、ファイルパスの間違ったパス、ファイル名または拡張機(jī)能、HTML構(gòu)文の問題、またはブラウザキャッシュによって引き起こされます。 1. SRCパスがファイルの実際の位置と一致していることを確認(rèn)し、正しい相対パスを使用します。 2.ファイル名のケースと拡張機(jī)能が正確に一致するかどうかを確認(rèn)し、URLに直接入力して畫像をロードできるかどうかを確認(rèn)します。 3.IMGタグ構(gòu)文が正しいかどうかを確認(rèn)し、冗長(zhǎng)文字がなく、ALT屬性値が適切であることを確認(rèn)してください。 4.ページを強(qiáng)制的に更新するか、キャッシュをクリアするか、Incognitoモードを使用してキャッシュ干渉を排除してください。この順序でのトラブルシューティングは、ほとんどのHTML畫像表示の問題を解決できます。

別のタグ內(nèi)にタグを入れることはできますか? 別のタグ內(nèi)にタグを入れることはできますか? Jul 27, 2025 am 04:15 AM

youcannotnesttagsinsisideantagbecuseit’sinvalidhtml; browsersautomatelycloseThefirsteforeopeningthenext、spedinginselementsied、useinlineelements like like like、orforstylingwithinaparagraph、またはblockainerslikegoriveparagragh

HTMLで順序付けられていないリストを作成する方法は? HTMLで順序付けられていないリストを作成する方法は? Jul 30, 2025 am 04:50 AM

HTML Unoderedリストを作成するには、タグを使用してリストコンテナを定義する必要があります。各リストアイテムはタグで包まれており、ブラウザは自動(dòng)的に弾丸を追加します。 1.タグを使用してリストを作成します。 2。各リスト項(xiàng)目はタグで定義されています。 3.ブラウザは、デフォルトのドットシンボルを自動(dòng)的に生成します。 4。サブリストはネスティングを通じて実裝できます。 5。CSSのリストスタイルタイプの屬性を使用して、ディスク、サークル、スクエア、またはなしなどのシンボルスタイルを変更します。これらのタグを正しく使用して、標(biāo)準(zhǔn)の非秩序化リストを生成します。

コンテンツ誘導(dǎo)性の屬性を使用する方法は? コンテンツ誘導(dǎo)性の屬性を使用する方法は? Jul 28, 2025 am 02:24 AM

thecontentEdentedItedItableattributemakesanyhtmlementedabledaitbyaddingcontenteditable = "true"、avainusErstodirectlymodifyContentinthebrowser.2.ItiscommonlyLichTexteditors、note-takingApps、およびin-place-placeditingintingintingintingintingintingtintingtintingtediv

SEOとアクセシビリティのセマンティックHTMLの重要性 SEOとアクセシビリティのセマンティックHTMLの重要性 Jul 30, 2025 am 05:05 AM

semantichtmlimprovesbothseoandaccessibilityを使用することはできません

html5 schema.orgマークアップを使用してカスタム語(yǔ)彙を定義します。 html5 schema.orgマークアップを使用してカスタム語(yǔ)彙を定義します。 Jul 31, 2025 am 10:50 AM

Schema.orgタグは、セマンティックタグ(アイテムスコープ、アイテムタイプ、アイテムプロップなど)を使用して、検索エンジンがWebページコンテンツの構(gòu)造化データ形式を理解するのに役立ちます。カスタム語(yǔ)彙を定義するために使用できます。方法には、既存のタイプの拡張や追加のタイプを使用して新しいタイプの導(dǎo)入が含まれます。実際のアプリケーションでは、構(gòu)造を明確に保ち、公式の屬性の使用を優(yōu)先し、コードの妥當(dāng)性をテストし、カスタムタイプにアクセスできるようにします。予防策には、部分的なサポートの受け入れ、綴りエラーの回避、JSON-LDなどの適切な形式の選択が含まれます。

HTMLフォームで検索入力フィールドを作成する方法 HTMLフォームで検索入力フィールドを作成する方法 Aug 02, 2025 pm 04:44 PM

usetheelementwithinatagtocreateasemanticsearchfield.2.includeaforAccessibility、settheform'sactionandmethod = "astributesenddatatoaseandpointwitharaibleableurl.3.addname =" q "dodefinethequeryparameter、umeplyholdertoguideuse

HTMLのリンクタグのREL屬性の目的は何ですか? HTMLのリンクタグのREL屬性の目的は何ですか? Aug 03, 2025 pm 04:50 PM

rel = "styleSheet" linkscssfilesforstylingthepage; 2.Rel = "preoad" hintstopreloadcriticalResourcesforPerformance; 3.REL = "ICON" setSthewebsite’sfavicon;

See all articles