Парсинг HTML в Java
Имеется задача каждые 10 минут доставать изображение радара с pogoda.by и скачивать в папку. Достать изображение не сложно, это я уже сделал вот так:
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) throws IOException{
URL url = new URL("https://pogoda.by/files/radars/static/33008/Radar_33008_MAP_PHEN_20220528_1440.png");
InputStream in = new BufferedInputStream(url.openStream());
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int n = 0;
while (-1!=(n=in.read(buf)))
{
out.write(buf, 0, n);
}
out.close();
in.close();
byte[] response = out.toByteArray();
FileOutputStream fos = new FileOutputStream("C:\\Users\\zucho\\OneDrive\\Рабочий стол\\RadarMaps\\test_map.png");
fos.write(response);
fos.close();
}
}
Но, основной проблемой является достать сам URL картинки. Для этого пытался использовать Jsoup, но результатов пока нет :
import java.io.IOException;
import java.net.URL;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class Main {
private static Document getPage() throws IOException {
String url ="https://pogoda.by/observation/radars/UMBB";
Document page = Jsoup.parse(new URL(url), 3000);
return page;
}
public static void main(String[] args) throws IOException{
Document page = getPage();
Element div = page.select("div[class=view]").first();
System.out.println(div);
}
}
HTML код сайта:
<app-view _nghost-serverapp-c6="" style="height: calc((100vh - 71px) - 49px); padding-top: 0px; display: block;">
<div _ngcontent-serverapp-c6="" class="wrapper-radar">
<div _ngcontent-serverapp-c6="" class="container-radar" style="min-height: calc(100% - 858px);">
<div _ngcontent-serverapp-c6="" class="section">
<div _ngcontent-serverapp-c6="" class="main-column">
<div _ngcontent-serverapp-c6=""><div _ngcontent-serverapp-c6="" class="player">
<div _ngcontent-serverapp-c6="" class="view">
<img _ngcontent-serverapp-c6="" src="//pogoda.by/files/radars/static/33008/Radar_33008_MAP_PHEN_20220529_0610.png">
</div> </div> </div> </div> </div> </div> </div> </app-view>