-
Notifications
You must be signed in to change notification settings - Fork 0
/
WikiImages.java
49 lines (31 loc) · 1.14 KB
/
WikiImages.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package ChatBot;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class WikiImages {
String word="";
public WikiImages(String word)
{
this.word=word;
}
public void imagesearch() throws Exception
{
String url="https://www.dreamstime.com/free-photos-images/"+word+".html";
Document document = Jsoup.connect(url).get();
String text = document.select("div").first().text();
System.out.println(text);
Elements img = document.getElementsByTag("img");
int count=0;
for (Element el : img) {
count++;
if(count>5) break;
//for each element get the src url
String src = el.absUrl("src");
ExecuteShellCommand ex=new ExecuteShellCommand(word);
ex.executeCommand("xdg-open "+src);
System.out.println("Image Found!");
System.out.println("src attribute is : "+src);
}
}
}