【问题标题】:Perform a search using JSoup使用 JSoup 执行搜索
【发布时间】:2015-05-01 11:52:18
【问题描述】:

由于 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,但到目前为止似乎没有一个可以工作。我该怎么做才能防止此消息弹出?

【问题讨论】:

  • 该页面始终包含您所感知的消息,只是不会在最近的浏览器中显示。
  • 为什么不使用 REST Client SDK 并使用他们的 REST API developers.soundcloud.com/docs/api/reference#playlists
  • @AllahbakshAsadullah 我怎样才能使用他们的其他 API 执行搜索?
  • here如何用api搜索。
  • @JonasCz 是的,这就是我所说的,这是使用 Javascript、Ruby、PHP 或 Python 时的方法,但他们的 Java API 已停止使用。

标签: java html jsoup user-agent


【解决方案1】:

你可以试试下面的sn-p。用户代理字符串取自 this 线程。

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-29
    • 1970-01-01
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    • 2017-10-14
    • 1970-01-01
    相关资源
    最近更新 更多