Jaunt API获取链接时?与=被转义为%3F%3D的技术咨询
Hey there, I’ve dealt with this exact problem using Jaunt before—those encoded %3F and %3D are just URL-encoded versions of ? and =, and Jaunt’s default behavior is to encode these characters when extracting href attributes. Here are two reliable solutions to get the raw, unencoded URL:
Option 1: Disable Automatic URL Encoding in Jaunt Settings
Jaunt’s UserAgent has a built-in setting that controls whether it automatically encodes URLs when pulling attributes like href. You can toggle this off globally before visiting your target page to stop the encoding at the source:
// Initialize your UserAgent instance UserAgent UA = new UserAgent(); // Disable automatic URL encoding UA.settings.encodeURLs = false; // Visit the Bloomberg page (or your target site) UA.visit("https://www.bloomberg.com/research/stocks/private/snapshot.asp?privcapId=7991464"); // Extract links as you originally did for (Element link : UA.doc.findEvery("<h3 class=r>").findEvery("<a>")) { String temp = link.getAt("href"); System.out.println(temp); // Now outputs unencoded ? and = directly }
This is the cleanest approach because it eliminates the encoding step entirely, rather than having to reverse it after the fact.
Option 2: Manually Decode the Encoded URL String
If you need to preserve some encoding or can’t modify global settings, you can use Java’s built-in URLDecoder class to reverse the encoding for each extracted link:
import java.net.URLDecoder; import java.io.UnsupportedEncodingException; // ... for (Element link : UA.doc.findEvery("<h3 class=r>").findEvery("<a>")) { String temp = link.getAt("href"); try { // Decode using UTF-8 (the standard encoding for web URLs) String decodedUrl = URLDecoder.decode(temp, "UTF-8"); System.out.println(decodedUrl); } catch (UnsupportedEncodingException e) { // Handle the exception (though UTF-8 is universally supported) e.printStackTrace(); } }
Quick Notes
- Jaunt’s
encodeURLssetting defaults totrue, which is why you’re seeing the encoded characters in your output. Disabling it tells Jaunt to return thehrefvalue exactly as it appears in the page’s HTML. - Stick with
UTF-8for decoding—it’s the standard character encoding for web content, so it’ll handle all common URL scenarios correctly.
内容的提问来源于stack exchange,提问作者Michael

