简体   繁体   English

使用JSoup执行搜索

[英]Perform a search using JSoup

Since the Soundcloud Java API is discontinued, I want to perform a search on their site using JSoup. 由于Soundcloud Java API已停产,因此我想使用JSoup在其站点上执行搜索。 I am currently using this code: 我目前正在使用此代码:

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

But the webpage is giving me a message that I should be using a newer browser: 但是该网页告诉我应该使用较新的浏览器的消息:

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

I have tried using other user agents which I found here but none seems to work so far. 我尝试使用在这里找到的其他用户代理,但到目前为止,似乎都没有用。 What can I do to prevent this message from popping up? 如何防止此消息弹出?

You can try the below snippet. 您可以尝试以下代码段。 User agent string taken from 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM