在Java中获取正确站点时遇到问题(网站搜索查询的第二个单词被切断)
我试图在西尔斯搜索我存储在字符串中的项目 我注意到每当我输入:在Java中获取正确站点时遇到问题(网站搜索查询的第二个单词被切断),java,html,search,jsoup,connect,Java,Html,Search,Jsoup,Connect,我试图在西尔斯搜索我存储在字符串中的项目 我注意到每当我输入: http://www.sears.com/search=summer clothes 在我的谷歌浏览器的搜索栏中,它会自动将其转换为: http://www.sears.com/search=summer%20clothes?catalogId=12605&storeId=10153&levels=Clothing&autoRedirect=true&viewItems=25&redirec
http://www.sears.com/search=summer clothes
在我的谷歌浏览器的搜索栏中,它会自动将其转换为:
http://www.sears.com/search=summer%20clothes?catalogId=12605&storeId=10153&levels=Clothing&autoRedirect=true&viewItems=25&redirectType=CAT_REC_PRED
因此,我的策略是让Jsoup获取这个站点并遵循重定向
String url = "http://www.sears.com/search=summer clothes";
Document document = Jsoup.connect(url).followRedirects(true).get();
然而,它实际带我去的网站是?。。。。有效地砍掉“衣服”
为什么会这样?我尝试过用%20替换URL中的空格,但这实际上会导致错误。他们可能使用JavaScript重定向。如果是这样,我该如何解决?您可以尝试Selenium或PhantomJS在emulator中运行此页面并获取结果,但这完全是另一回事。不幸的是,Jsoup对JS无能为力。