@@ -0,0 +1,2038 @@
+// Copyright 2019 Google LLC%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A//     https://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A%0Apackage com.google.sps.data;%0A%0Aimport java.io.IOException;%0Aimport org.jsoup.Jsoup;%0Aimport org.jsoup.nodes.Document;%0A%0A/**%0A * Class responsible for returning the Google Shopping results for a given query %0A * in the form of an HTML page. %0A */%0Apublic class GoogleShoppingResultsWrapper %7B%0A%0A  private static final String GOOGLE_SEARCH_URL = %22https://www.google.com//search%22;%0A  private static final String searchType = %22tbm=shop%22;%0A  private static final String tbs = %22tbs=vw:l%22; // %22tbs=vw%22 removes ads and specifies the viewing style.%0A  private static final String safetyCheck = %22safe=strict%22;%0A%0A  public static String getShoppingResultsPage(String shoppingQuery) throws IOException %7B%0A%0A    shoppingQuery = shoppingQuery.replaceAll(%22 %22,%22%2520%22);%0A    String languageParam = %22hl=en%22;%0A    String source = %22source=h%22;%0A    String query = %22q=%22 + shoppingQuery;%0A    String maxResultsNum = %22num=5%22;%0A%0A    String searchURL =%0A        GOOGLE_SEARCH_URL%0A            + %22?%22%0A            + searchType%0A            + %22&%22%0A            + tbs%0A            + %22&%22%0A            + safetyCheck%0A            + %22&%22%0A            + languageParam%0A            + %22&%22%0A            + source%0A            + %22&%22%0A            + query%0A            + %22&%22%0A            + maxResultsNum;%0A%0A    // Without proper User-Agent, it will result in a 403 error.%0A    Document doc = Jsoup.connect(searchURL).userAgent(%22Mozilla/5.0%22).get();%0A%0A    // Send back the HTML code of the search results.%0A    return doc.html();%0A  %7D%0A%7D%0A

Add Shopping Results Wrapper