Need your Help. I try to get SRC from site, but always get empty String. Whast I am doing wrong? My code:
try {
Document pageMeteo = Jsoup.connect("https://radar.veg.by/kiev/")
.userAgent("Chrome/4.0.249.0 Safari/532.5")
.referrer("http://www.google.com")
.get();
Element strImgHtml = pageMeteo.select("#scroller > div:nth-child(1) > div:nth-child(1) > img:nth-child(1)").first();
Elements strToGetImg = strImgHtml.getElementsByTag("img");
String src = strToGetImg.attr("scr");
if(src.isEmpty()){
sendMsg(message, "This str is empty!");
System.out.println("This str is empty!");
}else {
sendMsg(message, src);
System.out.println(src);
}
} catch (Exception e) {
e.printStackTrace();
}
Result is: This str is empty! ok, another code:
Elements strImgHtml = pageMeteo.select("#scroller > div:nth-child(1) > div:nth-child(1) > img:nth-child(1)");
for (Element el : strImgHtml) {
String src = el.attr("src");
Result is: This str is empty! ok, another way...
Elements strImgHtml = pageMeteo.select("#scroller > div:nth-child(1) > div:nth-child(1) > img:nth-child(1)");
Element srcToGetImg = strImgHtml.select("img.[src$=.png]").first();
String src = srcToGetImg.text();
Result: java.lang.IllegalArgumentException: String must not be empty At last:
Elements source = pageMeteo.select("#scroller > div:nth-child(1) > div:nth-child(1) > img:nth-child(1)");
if(source.hasText()){
System.out.println("text present");
}else {
System.out.println("no text");
}
Pattern p=null;
Matcher m= null;
String word0= null;
String word1= null;
p = Pattern.compile("<img[^>]*src=[\"']([^\"^']*)",
Pattern.CASE_INSENSITIVE);
m = p.matcher(source.toString());
while (m.find())
{
word0=m.group();
System.out.println(word0.toString());
}
if (source.isEmpty()) {
sendMsg(message, "This str is empty!");
System.out.println("This str is empty!");
} else {
sendMsg(message, source.toString());
System.out.println(source);
}
Relust: no text org.telegram.telegrambots.exceptions.TelegramApiRequestException: Error sending message: [400] Bad Request: can't parse entities: Unsupported start tag "img" at byte offset 0
why select source if empty? how to extract only src like a string I want to get source of this img -