Question

I'm trying to query a simple Google search using YQL but apparently it seems not working. Here's my exact query

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%27https%3A%2F%2Fwww.google.com/search?q=Google+Guice&ie=utf-8%27%0A&format=json 

And the error is

{"error":{"lang":"en-US","description":"Query syntax error(s) [line 1:74 mismatched character ' ' expecting ''']"}}

The error is pointing to line 1:74 which is near 20where. This is also the encoded version of the URL, and it is difficult for me to exactly understand where the error is.

Was it helpful?

Solution

Here's your url:

http://query.yahooapis.com/v1/public/yql?
q=select%20*%20from%20html%20where%20url%3D%27https%3A%2F%2F
www.google.com/search?q=Google+Guice&ie=utf-8%27%0A&format=json 

The URL query parts are separated into the following (separated by &):

+--------+---------------------------------------------------+
| q      | select%20*%20from%20html%20where%20url%3D%27https |
|        | %3A%2F%2Fwww.google.com/search?q=Google+Guice     |
+--------+---------------------------------------------------+
| ie     | utf-8%27%0A                                       |
+--------+---------------------------------------------------+
| format | json                                              |
+--------+---------------------------------------------------+

As you can see, YQL is not receiving the full query string as you wanted it to. This is because the & character that should be part of the query string has not been url-encoded to %26.

The URL should look like …Guice%26ie=utf….


Aside: There are a few other issues that you are going to face. The first is that the Google search URL embedded into the query is malformed since it will contain a literal space character between Google and Guice, which Google does not accept. Secondly, the URL is restricted by Google's robots.txt so even if the URL is fixed, you won't be able to get any results from there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top