Perform a search using JSoup

≯℡__Kan透↙ 提交于 2019-12-11 20:49:05

问题


Since the Soundcloud Java API is discontinued, I want to perform a search on their site using 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?


回答1:


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


来源:https://stackoverflow.com/questions/29986344/perform-a-search-using-jsoup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!