Hello
I want to develop a program in which I query a string to any search websites like Yahoo,Bing etc.. and get search results(only the websites) to display in a list box.So is there any way to get the search results ?

Thanks
From Satish

Dani AI

Generated

asked how to issue a query to search sites and get back the result URLs; pointed toward parsing raw results pages. Parsing HTML works but is brittle (layout changes, captchas, IP blocks) and can violate search-engine terms of service. For a reliable, long‑term solution use an official search API or a commercial SERP service.

Google and Microsoft both offer JSON web APIs that return structured results (the result URLs are in the JSON). Google’s Custom Search JSON API requires an API key and a search‑engine ID (CSE) and returns result items under items[].link — docs at Google Custom Search JSON API. Microsoft’s Bing Web Search API (Azure) provides similar JSON output with regional controls — docs at Bing Web Search API. If multiple engines must be queried through one interface, consider a commercial aggregator like SerpApi that handles engine variations and blocking for a fee.

A minimal Java 11+ example calling Google’s JSON API and printing links (replace API_KEY and CSE_ID and add a JSON library such as org.json or Jackson):

String apiKey = "API_KEY";
String cx = "CSE_ID";
String q = URLEncoder.encode("search terms", StandardCharsets.UTF_8);
String url = "https://www.googleapis.com/customsearch/v1?key=" + apiKey + "&cx=" + cx + "&q=" + q;

HttpClient client = HttpClient.newHttpClient();
HttpRequest req = HttpRequest.newBuilder(URI.create(url)).GET().build();
HttpResponse<String> resp = client.send(req, HttpResponse.BodyHandlers.ofString());
// parse resp.body() JSON -> iterate items[].link and collect URLs

Quick tips: URL‑encode queries, handle HTTP 4xx/5xx and rate limits (429), cache results, and monitor quota/cost. If scraping HTML is still attempted, keep it for one-off experiments only and be prepared for breakage; prefer official APIs for production.

Recommended Answers

All 3 Replies

HttpURLConnection and an HTMLParser ?

Hi masijade
Thanks for reply.But what I want is if I search a word in any search website(yahoo,google..) then it display some url address as search results.I actually want that URL address to display when I pass a word as a query to any search websites.

So parse those "results" to retreive those urls and Desktop.browse() to "open" them in browsers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.