Use Jsoup to solve picture link problems in Web pages

Source: Internet
Author: User
Tags webp

While doing Facebook and WhatsApp sharing, sharing the Google short chain, Facebook gets no big picture, and the competition is not the same as the display, WhatsApp to share the short chain without pictures and description.

WHATSAPP:

Analysis of the ucnews, found that they share the WhatsApp link to the page, the meat tag to add the relevant attributes, and then add the relevant tags in their own station, problem resolution.

<meta property= "Og:image" content= "Http://img.masala-sg.goldenmob.com/img/f6cb4bd725a7ab15dac6579f769a4c5f/i_ 0_mla_1480059457-608.jpg ">
<meta property= "Twitter:image" content= "http://img.masala-sg.goldenmob.com/img/ F6cb4bd725a7ab15dac6579f769a4c5f/i_0_mla_1480059457-608.jpg ">

Facebook:

Through multiple tests, it was found that Facebook was based on the size of the images in the Web pages of the shared links, and thus presented in different forms. I used to use a 480 of the picture, where you need to change all the images in the page to 608 of the larger image. Because the use of Ali's OSS, the image in the crawler storage has been processed, different image size is only the link suffix is different, so here involves the modification of the entire page of the image of the address.

The whole conten is a big json, and after I get to this side, I need to parse and replace the content in the tcontent.

{"image": [{"url": "Http://img.masala-sg.goldenmob.com/img/7bf6da255a03b8b93ffa985957da34a1/i_0_ 95db3c9b23b5de19685ca86fd1707c5b-208 "," W ": 480," H ": 216," s ": 23092},{" url ":" http://img.masala-sg.goldenmob.com/ Img/7bf6da255a03b8b93ffa985957da34a1/i_1_honeyjar-208.jpg "," W ": 362," H ": 331," s ": 76833},{" url ":"/HTTP/ img.masala-sg.goldenmob.com/img/7bf6da255a03b8b93ffa985957da34a1/i_2_718fdc7d637fe88f31c77eb90d8e22a0-208 "," W " : 480, "H": 274, "s": 24234},{"url": "Http://img.masala-sg.goldenmob.com/img/7bf6da255a03b8b93ffa985957da34a1/i_3_ muchgarlicpowderequalsoneclovegarlic_5c49a0162-208 "," W ":" Max "," H ": 394," S ": 31888}]," Tcontent ":" <p> </p><p></p> <p></p>\n<p>????? ?? ??? ?? ???? ?? ?????? ??? ??, ???? ???? ???? ????? ?? ??? ???? ?? ??? ???? ???? ??? </p>\n<p>??? ?? ?? ????? ????? ???? ??? ?? ???? ?? ??? ?? ???? ?? ???? ??? ??? ???? ???? ??, ???? ??? ???? ?? ?? ???? ??????? ??????? ????? ?? ??? ??? ??? ??????? ??????? ????? ?? ???? ?? ?? ????? ?? ?? ??? ?? ????????? ??? ???? ???? ?? ????? ?? ????? ??? ?? ????? ?? ??? ?? ?? ??? ???? ?? ???? ?? ?? ??????????? ?? ??? ???? ???? ?? ?? ?????? ?? ???? ??? ??? </p>\n<p></p>\n<p>??? ????? ?? ???? ???? 2-3???? ????? ?? ??? ?? ?????? ?? ??? ?? ??? ?????? ?? ??? ????? ????? ?????? ??? ???????? ??? ??? ??? ?? ???? ??? ?? ???? ??????, ????? ????? ??? ???? ??? ??? ???? ??? ??? ???? ???? ??? 7????? ?? ????? ?? ??? ?????? ????? ????? ?????? ?? ????? ??? ?? ?? ?????? ???? ???????? ?? ???????????? ?? ?? ???? ?? ??? ???? ??? ??? ?? ??? ???? ?? ??? ?? ?? ???? ??? </p>\n<p> </p><p></p> <p></p>\n<p>????? ?? ??? ?? ??? ?? ?? ??? ?? ?????? ?? ???? ?? ?? ??? ?? ??????? ??????? ?? ????? ?? ???? ??? ??????? ??????? ????? ???? ?? ???? ???? ?? ??? ?? ??? ???? ?? ?? ??? ??? ?????? ???? ????? ?? ?????? ?? ???? ?? ???? ?? ???? ???? ??????? ??? ??? ??? ???? ???? ??, ????? ??? ?? ?????? ??? ?????? ?? ???? ?? ????? ???? ??? ???? ???? ?? ??????? ???? ??? </p>\n<p>?? ?????? ?? ???? ?? ??? ?? ??????? ??? ???? ?? ???????? ????? ???? -??????????? ??? ???? ?? ??? ?? ???? ?? ???? ?? ?? ???? ??? ??? ???? ?? ??????? ?? ??? ?? ??, ??? ???? ?????? ??????? ???? ???? ???? ????? ???????? ?? ????? ?? ??? ?? ??????? ?? ??????? ???? ???? ?? ????? -????? ?? ??? ????? ?? ????? ?? ???? ?? ?? ???? ??? </p>\n<p> "}
Content

Initial scenario:

Use the ReplaceAll method of string directly, replace 480 with 608, and add a link to a picture without a suffix. webp. There are no problems when testing, but after the project is online, the following errors are often found on the OSS side. Analysis found that the original existence of such a situation This picture does not have a suffix, in the replacement can only replace 480 for 608, but can not add the suffix, so that when the Web page access, Browser request image address will automatically take the HTML code behind to request OSS. This is generally the case in Hindi and Malate, where there is a partial Unicode encoding in the content, trying to transcode, regular, but not perfect.

/img/7bf6da255a03b8b93ffa985957da34a1/i_2_718fdc7d637fe88f31c77eb90d8e22a0-608.%3e%3c/p%3e%3cp%3e%3c/p%3e%20% 3cp%3e%3c/p%3e%3cp%3e%e0%a4%b2%e0%a4%b9%e0%a4%b8%e0%a5%81%e0%a4%a8%20%e0%a4%94%e0%a4%b0%20%e0%a4%b6%e0%a4%b9% E0%a4%a6%20%e0%a4%95%e0%a5%87%20%e0%a4%ae%e0%a5%87%e0%a4%b2%20%e0%a4%b8%e0%a5%87%20%e0%a4%87%e0%a4%b8%20%e0%a4 %98%e0%a5%8b%e0%a4%b2%20%e0%a4%95%e0%a5%80%20%e0%a4%b6%e0%a4%95%e0%a5%8d%e2%80%8d%e0%a4%a4%e0%a4%bf%20%e0%a4% Ac%e0%a4%a2%20%e0%a4%9c%e0%a4%be%e0%a4%a4%e0%a5%80%20%e0%a4%b9%e0%a5%88%20%e0%a4%94%e0%a4%b0%20%e0%a4%ab%e0%a4 %bf%e0%a4%b0%20%e0%a4%af%e0%a4%b9%20%e0%a4%87%e0%a4%ae%e0%a5%8d%e2%80%8d%e0%a4%af%e0%a5%82%e0%a4%a8%20%e0%a4% B8%e0%a4%bf%e0%a4%b8%e0%a5%8d%e2%80%8d%e0%a4%9f%e0%a4%ae%20%e0%a4%95%e0%a5%8b%20%e0%a4%ae%e0%a4%9c%e0%a4%ac%e0 %a5%82%e0%a4%a4%20%e0%a4%95%e0%a4%b0%20%e0%a4%a6%e0%a5%87%e0%a4%a4%e0%a4%be%20%e0%a4%b9%e0%a5%88%e0%a5%a4%20% e0%a4%87%e0%a4%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5%87%20%e0%a4%b9%e0%a5%88%e0%a4%82%e0%a5%a4%20%e0%a4%af%e0%a4%b9%20%e0%a4 %8f%e0%a4%95%20%e0%a4%aa%e0%a5%8d%e0%a4%b0%e0%a4%95%e0%a4%be%e0%a4%b0%20%e0%a4%95%e0%a4%be%20%e0%a4%b8%e0%a5% 82%e0%a4%aa%e0%a4%b0%20%e0%a4%ab%e0%a5%82%e0%a4%a1%20%e0%a4%b9%e0%a5%88%e0%a5%a4%3c/p%3e%3cp%3e%3cimg%20src=
OSS Error

After improvement (using Jsoup):

After the improvement, using Jsoup to parse the entire HTML code, and then get to the image address, replace it and add a suffix, the perfect solution to the problem.

 Public Staticstring Replaceimgofcontent (string content) {Document doc=jsoup.parsebodyfragment (content); Elements img= Doc.getelementsbytag ("img");  for(Element link:img) {link.removeattr ("Data-src"); Link.removeattr ("Data-lazy-src"); Link.removeattr ("Alt"); Link.removeattr ("Title"); Link.removeattr ("Src-set"); Link.removeattr ("id"); Link.removeattr ("Class"); String Linkhref= Link.attr ("src"); if(!linkhref.endswith (". gif")){                if(Linkhref.indexof ("MASALA-SG") > 0) {                    intSize = Linkhref.lastindexof ("."); if(Linkhref.length ()-size < 10) {String im= Linkhref.substring (size-3, Linkhref.lastindexof ("."))); if(Im.equals ("480") ) {String Idu= Linkhref.substring (Linkhref.lastindexof ("480"), Linkhref.length ()); Linkhref= Linkhref.replace (Idu, "608.WEBP"); }                    } Else {                        if(Linkhref.endswith ("480") ) {Linkhref= Linkhref.replaceall ("480", "608"); Linkhref= linkhref+ ". Webp"; }} link.attr ("SRC", Linkhref); }}} Content=doc.body (). HTML (). toString (); returncontent; }
View Code

Jsoup Cookbook (Chinese version): http://www.open-open.com/jsoup/

Maven dependency:
<dependency> <groupId>org.jsoup</groupId> <artifactId>jsoup</artifactId> <version>1.10.2</version></dependency>

   

Use Jsoup to solve picture link problems in Web pages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.