0

我正在使用以下代码:

String zip = "75227";
String str = "http://query.yahooapis.com/v1/public/yql?q=select%20Title%2C%20Address%2C%20" +
            "City%2C%20State%2C%20Phone%2C%20Distance%20from%20local.search%20where%20query%3D%22" +
            "food%20pantries%22%20and%20zip%3D%22" + zip +"%22%20and%20(category%3D%2296927050%22%20or" +
            "%20category%3D%2296934498%22)%20%7C%20sort(field%3D%22Distance%22)";

Document doc = Jsoup.connect(str).get(); 

它通过替换邮政编码值产生了我想要的结果。我也想换个位置。我尝试通过执行以下操作对邮政编码做同样的事情:

String zip = "32207";

String service = "food pantry";

String testOne = "http://query.yahooapis.com/v1/public/yql?q=select%20Title%2C%20Address%2C%20" +
            "City%2C%20State%2C%20Phone%2C%20Distance%20from%20local.search%20where%20query%3D%22" +
            service + "%22%20and%20zip%3D%22" + zip +"%22%20and%20(category%3D%2296927050%22%20or" +
            "%20category%3D%2296934498%22)%20%7C%20sort(field%3D%22Distance%22)";

当以这种方式使用时,变量“服务”给了我一个错误。

我最初尝试像这样使用 yql 表:

String search = "http://query.yahooapis.com/v1/public/yql?q=";
String table = "select Title, Address, City, State, Phone, Distance from local.search where " +
            "query=\"food pantries\" and zip=\"75227\" and (category=\"96927050\" or category=" +
            "\"96934498\") | sort(field=\"Distance\")";

String searchText = search + table;

更新:

这是我得到的错误:

Exception in thread "main" org.jsoup.HttpStatusException: HTTP error fetching URL. Status=505, URL=http://query.yahooapis.com/v1/public/yql?q=select%20Title%2C%20Address%2C%20City%2C%20State%2C%20Phone%2C%20Distance%20from%20local.search%20where%20query%3D%22food pantry%22%20and%20zip%3D%2232207%22%20and%20(category%3D%2296927050%22%20or%20category%3D%2296934498%22)%20%7C%20sort(field%3D%22Distance%22)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:418)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:393)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:159)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:148)
at org.jsoup.examples.HtmlToPlainText.main(HtmlToPlainText.java:86)

但是,这也不起作用。关于如何进行此搜索并将服务和邮政编码作为变量提供的任何想法?

4

1 回答 1

0

你试过用 替换String service = "food pantry";String service = "food%20pantry";

编辑:

它是“食品储藏室”还是“食品储藏室”……?

于 2012-11-05T17:04:24.970 回答