Suppose if I made a connection using the following code :
Document document = Jsoup.connect(url)
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36")
.timeout(120*1000)
.followRedirects(true)
.get();
and now I want to extract the url with which I made connection with Jsoup, how can I do that ?
The only url (in this case as a String
) you can obtain from a jsoup document
is using the location() method, being aware of possible redirects that can bring an url different from the starting url:
Get the URL this Document was parsed from. If the starting URL is a redirect, this will return the final URL from which the document was served from.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.