是否可以将UserAgent添加到YQL? [英] Is it possible to add UserAgent to YQL?

查看:112
本文介绍了是否可以将UserAgent添加到YQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用跨域-ajax 其中,正在使用YQL。

它有这一行:

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="*"';

所以我在下面添加了 user-agent

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"';

现在它不再返回值:(

我的主要javascript是这样的:

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;    
});

如何将用户代理添加到YQL?

我想这样做的原因是因为HTML源的内容因用户代理而异正在使用。

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.

我想要使用智能手机访问HTML源代码。

I want the HTML source when it's being accessed with smartphone.

推荐答案

在我看来,这是不可能的(至少 非HTML 数据)。

It appears to me that this is not possible (at least for non-HTML data).

根据 YQL参考,YQL访问'非HTML用户代理 Yahoo Pipes 2.0 下的数据(即css,xml 甚至robots.txt!)。

请注意它不关心'robots.txt'规则,因为它不是抓取工具。

因此,当访问'HTML-Data'和robots.txt时检查阻止 Yahoo Pipes 2.0 访问您的内容,然后使用其他用户代理获取目标页面:

Mozilla /5.0(Windows; U; Windows NT 5.1; EN-US; rv:1.8.1.14)Gecko / 20080404 Firefox / 2.0.0.14

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

作为解决方法,您可以在使用PHP之间设置自己的代理,你可以看一下 curl_setopt CURLOPT_USERAGENT (让yahoo托管YQL查询您的代理服务器)或者在您的服务器上安装YQL版本(使其成为您的托管YQL并修改API以处理您的UA参数)。

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).

这篇关于是否可以将UserAgent添加到YQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆