JavaScript查找您的Yahoo! 排行

news/2024/7/19 16:34:31 标签: java, python, php, javascript, js

动机(Motivation)

Inspired by this article on SitePoint that shows how to find the Google ranking for a specific page and a search query, I decided to do the same, but for the Yahoo! ranking. The fun part is that my script is a JavaScript and requires nothing but a browser in order to run.

受SitePoint上这篇文章的启发,该文章展示了如何为特定页面和搜索查询找到Google排名,我决定这样做,但对于Yahoo! 排行。 有趣的部分是我的脚本是JavaScript,并且只需要一个浏览器即可运行。

我的与众不同 (How mine is different)

In the article above you need to use Google's SOAP service, so if you're not lucky enough to be running PHP5, you'll probably need something along the lines of PEAR SOAP or NuSOAP. That implies you also need a web server, running PHP. Then you need a Google API key and you need to download stuff and upload it to your server.

在上面的文章中,您需要使用Google的SOAP服务,因此,如果您不足够幸运地无法运行PHP5,则可能需要使用PEAR SOAP或NuSOAP。 这意味着您还需要一个运行PHP的Web服务器。 然后,您需要一个Google API密钥,并且需要下载内容并将其上传到您的服务器。

Nothing even close to that in terms of requirements if you opt in for the Yahoo! web service. All you need is a browser and JavaScript enabled, which shouldn't be a big deal, I don't think 😉

如果您选择使用Yahoo !,就要求而言,甚至没有什么比这更好的了。 网络服务。 您所需要做的只是启用浏览器和JavaScript,这没什么大不了的,我认为don

关于Yahoo! JSON Web服务 (About the Yahoo! JSON web service)

Yahoo's web service can return XML as everybody else, but it can also return serialized PHP and also JSON. Using the JSON option you can make a simple XMLHTTPRequest and get all the content JavaScript-ready, without the headaches of getELementsByTagName() or other DOMmy methods to wrestle that XML tree. The problem here is that you're requesting a file from a different domain, so the browser won't allow it. Workaround - a simple PHP script to serve as a proxy. Oooor (as we said we don't need no stinkin' server) you can use the dynamic JavaScript includes (discussed here) to do the request. As a result you get a working solution with JS only.

Yahoo的Web服务可以像其他所有人一样返回XML,但是它也可以返回序列化PHP和JSON。 使用JSON选项,您可以创建一个简单的XMLHTTPRequest并获取所有可用于JavaScript的内容,而无需费力地处理XML树的getELementsByTagName()或其他DOMmy方法。 这里的问题是您要从其他域请求文件,因此浏览器不允许这样做。 解决方法-一个简单PHP脚本作为代理。 Oooor(正如我们所说,我们不需要任何讨厌的服务器),您可以使用动态JavaScript包含项(在此处讨论)来执行请求。 结果,您只能使用JS获得有效的解决方案。

By the way, if you're wondering about the beauty of JSON, try this eye-opener.

顺便说一句,如果您想了解JSON的美丽之处,请尝试使用这款令人大开眼界的产品。

演示版 (Demo)

Ah, yes, the demo is here.

啊,是的,演示在这里。

Enter a/ your URL, or part of it, and b/ a search query. Then the script will tell you where in the first 1000 results is your URL to be found. If it is found.

输入a /您的URL或部分URL,然后b /搜索查询。 然后,脚本将告诉您在前1000个结果中可以找到您的URL的位置。 如果找到。

怎么运行的 (How it works)

Check the source for the details, it's reasonably well commented, but the big picture:

检查来源以了解详细信息,它的注释相当合理,但总的来说:

  • You make a request (in yjsonrank.makeRequest()) by appending a new SCRIPT element to the HEAD of your HTML. The URL of the script element (the SRC attribute) points to the Y! web service and also passes the search query and a function to be called once the script is included. This function happens to be yjsonrank.process()

    通过在HTML的HEAD后面附加一个新的SCRIPT元素来发出请求(在yjsonrank.makeRequest() )。 脚本元素的URL(SRC属性)指向Y! Web服务,并传递搜索查询和包含脚本后要调用的函数。 该函数恰好是yjsonrank.process()

  • The yjsonrank.process() function receives JSON data returned by the service, assigned to the resp variable.

    yjsonrank.process()函数接收服务返回的JSON数据,并分配给resp变量。

  • We loop through resp.ResultSet, checking every resp.ResultSet.Result if its Url property contains our URL. If yes - we're done! If not, we make another request this time for the next 50 results. (50 is randomly chosen, feel free to modify). We continue until we reach 1000th result, which is the max that Y! will be willing to give.

    我们遍历resp.ResultSet ,检查每个resp.ResultSet.ResultUrl属性是否包含我们的URL。 如果是-我们完成了! 如果没有,我们这次再次请求下一个50个结果。 (随机选择50个,随时进行修改)。 我们继续直到达到第1000个结果,这就是Y的最大值! 愿意付出。

And that's pretty much it, the rest is just fluff and beautifications 😉

就是这样,其余的只是绒毛和美化😉

更多Y! 信息 (More Y! info)

  • The JSON description

    JSON描述

  • The Web Search API page, listing all the additional parameters you can add to your search request and what format would have the result

    Web Search API页面,列出了您可以添加到搜索请求中的所有其他参数以及结果的格式

谢谢阅读!(Thanks for reading!)

Tell your friends about this post on Facebook and Twitter

在Facebook和Twitter上告诉您的朋友有关此帖子的信息

翻译自: https://www.phpied.com/javascript-to-find-your-yahoo-ranking/


http://www.niftyadmin.cn/n/1307056.html

相关文章

FusionCharts 2D柱状图和折线图的组合图

1、设计思路 &#xff08;1&#xff09;了解组合图的特性以及用法&#xff0c;选用图的类型&#xff1b; &#xff08;2&#xff09;设计出两根柱子和两根折线&#xff0c;分开展示。 2、设计步骤 &#xff08;1&#xff09;设计页面 Column2DLine.html&#xff1a; <!…

设计模式一览

设计模式一览 CS-NOTESDesign patterns implemented in JavaDesign Patterns 一、概述 设计模式是解决问题的方案&#xff0c;学习现有的设计模式可以做到经验复用。 拥有设计模式词汇&#xff0c;在沟通时就能用更少的词汇来讨论&#xff0c;并且不需要了解底层细节。 二、…

windows密钥即将到期_更新即将到期的组件

windows密钥即将到期NOTE: This is late night mumbling from a week or two ago, leaving here for posterity. Dont read it. Meanwhile Steve wrote up a proper blog post which is highly recommended: Self-updating scripts. Read his post instead! 注意&#xff1a;这…

FusionCharts 2D柱状图和折线图的组合图调试错误

在设计FusionCharts 2D柱状图和折线图的组合图的时候&#xff0c;我发现不管怎么重启服务器&#xff0c;组合图就是不出来。后来&#xff0c;我通过调试发现我犯了一个致命的错误&#xff0c;运用平常一贯的思维&#xff0c;认为3D图有这种类型&#xff0c;那么2D也有这种类型&…

减少页面组件的数量

2010 update: Lo, the Web Performance Advent Calendar hath moved 2010年更新&#xff1a; Lo&#xff0c; Web Performance Advent Calendar已移动 Dec 5 This is the fifth in the series of performance articles as part of my 2009 performance advent calendar experim…

程序员最该看的30本书---------------------------国外编辑推荐

“如果能时光倒流&#xff0c;回到过去&#xff0c;作为一个开发人员&#xff0c;你可以告诉自己在职业生涯初期应该读一本&#xff0c;你会选择哪本书呢&#xff1f;我希望这个书单列表内容丰富&#xff0c;可以涵盖很多东西。”很多程序员响应&#xff0c;他们在推荐时也写下…

jest单元测试_Jest + jQuery,用于测试香草“应用”

jest单元测试Jest is a new javascript testing tool announced today. I thought Id take it out for a spin testing the UI of a simple vanilla JS app - no CommonJS modules, no fancy stuff. Just old school JavaScript. Granted, its probably not what the tool was …

Action调用Service

Java Web项目&#xff0c;写到Action的时候&#xff0c;往往会要引入Service&#xff0c;这个是一个常见的操作。 但是&#xff0c;我自认为引入Service需要给它get和set方法&#xff0c;并且这个习惯已经沿用到现在。然而&#xff0c;自从参与了dojo这个项目&#xff0c;这种写…