使用 JSoup 执行搜索

Perform a search using JSoup

由于 Soundcloud Java API 已停产,我想使用 JSoup 在他们的网站上进行搜索。我目前正在使用此代码:

Document doc = Jsoup
            .connect("https://soundcloud.com/search?q=deep%20house")
            .userAgent("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36")
            .timeout(5000).get();

但是网页提示我应该使用更新的浏览器:

<p class="messageText sc-text-light">Your current browser isn't compatible with SoundCloud.<br>Please download one of our supported browsers. <a href="http://help.soundcloud.com/customer/portal/articles/552882-the-site-won-t-load-for-me-all-i-see-is-the-soundcloud-logo-what-can-i-do-">Need help?</a></p>

我曾尝试使用我发现的其他用户代理 here,但 none 目前似乎还可以。我该怎么做才能防止弹出此消息?

您可以试试下面的代码片段。用户代理字符串取自 this thread.

Document doc = Jsoup
                .connect("https://soundcloud.com/search?q=deep%20house")
                .userAgent("Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19")
                .timeout(5000).get();
System.out.println(doc);