4

I need to extract search results from Bing. Is there any available Java code to achieve this ?

Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
Jury A
  • 19,192
  • 24
  • 69
  • 93

1 Answers1

7

This MSDN forum thread has alot of answers and examples.

Also, when you buy or subscribe to a dataset on Azure, they have a java example. Here's an example

Go to the odata4j site and download the latest release.

Add odata4j-clientbundle-x.x.jar to your Java build path.

You can use the following code to call the service.

ODataConsumer c = ODataConsumers
    .newBuilder("https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/")
    .setClientBehaviors(OClientBehaviors.basicAuth("accountKey", "{your account key here}"))
    .build();

OQueryRequest<OEntity> oRequest = c.getEntities("Web")
    .custom("Query", "stackoverflow bing api");

Enumerable<OEntity> entities = oRequest.execute();
Nathan Black
  • 440
  • 3
  • 6
  • Quite hard to find a working example, and that is one perfectly working one! Thanks. – YMomb Apr 18 '13 at 15:08
  • Remember to encode your query and add `'` to the beginning and end of the query. `String query = URLEncoder.encode("'stackoverflow bing api'", "UTF-8");` See http://stackoverflow.com/questions/10786042/java-url-encoding-of-query-string-parameters for more details. – Peeter Kokk Feb 02 '16 at 12:51