问题
I'm using cross-domain-ajax in which, YQL is being used.
It has this line in it:
query = 'select * from html where url="{URL}" and xpath="*"';
so I added user-agent to it like this below:
query = 'select * from html where url="{URL}" and xpath="*" and ua="Mozilla/5.0 (Linux; U; Android 4.0.1; ja-jp; Galaxy Nexus Build/ITL41D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"';
Now it won't return the value any more :(
My main javascript is this:
url = 'http://foofoofoofoofoofoo.com';
var content ='';
$.get(url, function(data){
content = data.responseText;
});
How can I add user-agent to YQL?
The reason why I want to do it is because the content of HTML sources differ depending on which user-agent is being used with.
I want the HTML source when it's being accessed with smartphone.
回答1:
It appears to me that this is not possible (at least for non-HTML data).
According to the YQL reference, YQL accesses 'non-HTML' data under User-Agent Yahoo Pipes 2.0
(that is css, xml and even robots.txt!).
Note that it doesn't care for the 'robots.txt' rules as it isn't a crawler.
Therefore, when accessing 'HTML-Data' and the robots.txt check prevents Yahoo Pipes 2.0
from accessing your content, it will then fetch the target page using a different user agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14
As workaround you could set up your own proxy in between using PHP, you'd have a look at curl_setopt CURLOPT_USERAGENT (making yahoo hosted YQL query your proxy instead) OR install version of YQL on your server (making it your hosted YQL AND modify the API to handle your UA parameter).
来源:https://stackoverflow.com/questions/29345092/is-it-possible-to-add-useragent-to-yql