使用JSoup执行搜索 [英] Perform a search using JSoup
本文介绍了使用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,如Gecko)Chrome / 41.0.2228.0 Safari / 537.36)
。超时(5000)获得();
但是网页给了我一个消息,告诉我应该使用更新的浏览器:
< p class =messageText sc-text-light>您目前使用的浏览器与SoundCloud不兼容< br>请下载我们支持的浏览器之一。 < 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 - >需要帮助吗?< / a>< / p>
我曾尝试使用其他用户代理,我发现这里,但似乎目前没有工作。我可以做些什么来防止此消息弹出?
你可以试试下面的代码片段。来自 此 的用户代理字符串线程。
Document doc = Jsoup
.connect(https://soundcloud.com/search?q=深度%20house)
.userAgent(Mozilla / 5.0(Linux; Android 4.1.1; Nexus 7 Build / JRO03D)AppleWebKit / 535.19(KHTML,如Gecko)Chrome / 18.0.1025.166 Safari / 535.19)
.timeout(5000).get();
System.out.println(doc);
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?
解决方案
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);
这篇关于使用JSoup执行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文