You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jaunt API获取链接时?与=被转义为%3F%3D的技术咨询

Fixing URL Encoding Issues with Jaunt API for Special Characters

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 encodeURLs setting defaults to true, which is why you’re seeing the encoded characters in your output. Disabling it tells Jaunt to return the href value exactly as it appears in the page’s HTML.
  • Stick with UTF-8 for decoding—it’s the standard character encoding for web content, so it’ll handle all common URL scenarios correctly.

内容的提问来源于stack exchange,提问作者Michael

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:52:15