Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build your own Aleax query service for a website

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to build your own Aleax query service for the website", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to build your own Aleax query service for the website" this article.

1. Alexa introduction

Alexa (http://www.alexa.com/)) is a website that publishes the ranking of world websites. Alexa, which started as a search engine, was founded in April 1996 (USA) to enable Internet users to participate in the organization of Internet resources while sharing virtual world resources. Alexa collects more than 1TB information online every day, not only giving billions of URL links, but also ranking each of them. It can be said that Alexa is currently the website with the largest number of URL and the most detailed ranking information.

In 1999, Alexa was acquired by Amazon, the flagship US e-commerce company, and became a wholly owned subsidiary of the latter. In the spring of 2002, Alexa abandoned its search engine and partnered with Google instead.

Alexa provides the service of website traffic statistics, which records the traffic of websites with domain names around the world. In other words, as long as you apply for a domain name, you can look up the ranking of your website in Alexa. Alexa's site rankings are based on the number of views on each particular site. The higher the pageview rate, the higher the ranking.

Usually, if your domain name has just been registered, the ranking is more than 10 million; next, you run the website carefully every day, and when it gets better, you will enter the top 1 million; then, you continue to publish quality content and stick to it for a period of time. The ranking will rise to the top 500000. When your website is well-known in a certain field, the ranking can reach 100000, such as fan log 122616 (2015-10-25), then advertisers will be willing to put ads; if you are doing a for-profit site, then you need to refuel, enter the top 10, 000, this time your traffic can bring you business If you can do better, enter the top 2000, such as Snowball to 2109 (2015-10-25), then you will have a high valuation; if you can catch up with a big opportunity, your website will rank in the top 100. then your website will bring you the value of listed companies, such as JD.com (2015-10-25). If you are a talented CEO and the website is in the top 10, then you will become the richest person in an industry or even in a region, such as Baidu 4 (2015-10-25).

Come on, stationmasters!

two。 Developing Alexa Services with Node

2.1 Alexa Open API

Alexa website ranking is generally recognized by the industry, ranking data will be often cited, every time on the site query will appear inconvenient. Alexa API provided by Amazon allows developers to build their own Alexa query applications.

Alexa has two main data API services.

Alexa Web Information Service, which queries the ranking information of a single website

Alexa Top Sites, the comprehensive ranking of query sites

Usually, you only need to call the UrlInfo data interface to get the traffic data of the website. Of course, the definition of this interface is not as easy to use as I thought, and the open data is limited.

The API of the UrlInfo interface, as shown in the following figure.

The official SDK toolkit is available in multiple languages, and I think Node.js is the most convenient. An Alexa data query service I built, http://fens.me/alexa

2.2 create an API key for AWS

Before we can use AWS's API, we need to create a key, which is similar to OAuth3's access mechanism.

1. To register an AWS account, please complete it by yourself. Register

two。 Enter the AWS account management console, console

3. Select Security Certificate from the console

4. Create access keys (access keys ID and private access keys)

When we write the program later, we need to enter the created access key ID and private access key.

Developing Alexa Services with Node

Next, I'll introduce you to build an Alexa project with Node.

My system environment

Win10 64bit

Node v0.12.3

NPM 2.9.1

Create a project

~ D:\ workspace\ nodejs > mkdir nodejs-alexa & & cd nodejs-alexa

Create a new Node project profile: package.json

~ vi package.json {"name": "alexa-demo", "version": "0.0.1", "description": "alexa web demo", "license": "MIT", "dependencies": {"awis": "0.0.8"}}

Install awis package

~ D:\ workspace\ nodejs\ nodejs-alexa > npm install npm WARN package.json alexa-demo@0.0.1 No repository field. Npm WARN package.json alexa-demo@0.0.1 No README data alexarank@0.1.1 node_modules\ alexarank ├── xml2js@0.4.13 (sax@1.1.4, xmlbuilder@3.1.0) └── request@2.30.0 (forever-agent@0.5.2, aws-sign2@0.5.0, qs@0.6.6, tunnel-agent@0.3.0, oauth-sign@0.3.0, json-stringify-safe@5.0.1 Mime@1.2.11, node-uuid@1.4.3, tough-cookie@0.9.15, form-data@0.1.4, hawk@1.0.0, http-signature@0.10.1) awis@0.0.8 node_modules\ awis ├── xml2js@0.4.13 (sax@1.1.4, xmlbuilder@3.1.0) ├── lodash@3.10.1 └── request@2.65.0 (aws-sign2@0.6.0 Forever-agent@0.6.1, caseless@0.11.0, stringstream@0.0.4, oauth-sign@0.8.0, tunnel-agent@0.4.1, isstream@0.1.2, json-stringify-safe@5.0.1, extend@3.0.0, node-uuid@1.4.3, qs@5.2.0, tough-cookie@2.2.0, combined-stream@1.0.5, mime-types@2.1.7 Form-data@1.0.0-rc3, http-signature@0.11.0, hawk@3.1.0, bl@1.0.0, har-validator@2.0.2)

Create a new file alexa.js and call AWS Alexa website ranking API.

~ vi alexa.js / / define AWS key var key = 'xxxxxxxxxxxxxxx'; var sercet =' xxxxxxxxxxxxxxx'; / / create awis instantiated object var awis = require ('awis'); var client = awis ({key: key, secret: sercet}); / / call UrlInfo interface console.log ("= UrlInfo=") Client ({'Action':' UrlInfo', / / UrlInfo API 'Url':' fens.me', / / queried website 'ResponseGroup':' TrafficData,ContentData' / / required data set}, function (err, data) {if (err) console.log (err); console.log (data);})

Run the program node alexa.js

~ D:\ workspace\ nodejs\ nodejs-alexa > node alexa.js = UrlInfo= {contentData: {dataUrl: 'fens.me', siteData: {title:' fan log', description: 'cross-border IT blog | Hadoop family, R, RHadoop, Nodejs, AngularJS, NoSQL, IT Finance'}, speed: {medianLoadTime: '982, percentile:' 70'}, adultContent:', language:'' LinksInCount: '1988, keywords:', ownedDomains:'}, trafficData: {dataUrl: 'fens.me', rank:' 122616, usageStatistics: {usageStatistic: [Object]}, contributingSubdomains: {contributingSubdomain: [Object]}

Simply a few lines of code, all get the ranking information of Alexa. When printing in the background, the Object did not go to the object, I made a service, you can view the full return through the HTTP output. Http://api.fens.me/alexa/fens.me

We check the source code of the awis package and find that, in fact, the AWS Alexa service returns XML,awis automatically to help us do the transformation of JSON. If you want to view the original return value, you can modify the parse () function of the index.js file in the awis package.

Function parse (xml, req, cb) {console.log (xml); / / print. }

Run the program

D:\ workspace\ nodejs\ nodejs-alexa > node alexa.js = UrlInfo= 1e7d8406-4b62-3460-27fb-325fc3dc3e85 fens.me fan log cross-border IT blog | Hadoop family, R, RHadoop, Nodejs, AngularJS, NoSQL IT Finance 982 70198 fens.me 122616 3 122616 + 28849 110056 + 25785 12.5-24.68% 0.27-24.84% 194189 43945 1.9% 1 102621-30257 95663-20326 15 + 20 153976-69981 2.2 + 30% 7 114709 + 32390 103552 + 27312 14-28.59% 0.3-37.28% 188124 58655 2.0-12.11% 1 74860-93163 70563-54001 20 + 60% 0.6 + 300% 111541-210757 2 + 100% Blog.fens.me 1 99.19% 99.64% 2.2 OTHER 1 0 0.36% 0 Success

There are several interfaces that can be used in addition to the UrlInfo interface.

TrafficHistory interface

Console.log ("= TrafficHistory="); client ({'Action':' TrafficHistory', 'Url':' fens.me', 'ResponseGroup':' History'}, function (err, res) {if (err) console.log (err); console.log (res.trafficHistory); console.log (res.trafficHistory.range); console.log (res.trafficHistory.site); console.log (res.trafficHistory.start) Console.log (res.trafficHistory.historicalData); console.log (res.trafficHistory.historicalData.data); console.log (res.trafficHistory.historicalData.data.length); res.trafficHistory.historicalData.data.forEach (function (item) {console.log (item.date); console.log (item.pageViews); console.log (item.rank); console.log (item.reach);});})

Run the program

~ D:\ workspace\ nodejs\ nodejs-alexa > node alexa.js = TrafficHistory= {range:'31, site: 'fens.me', start:' 2015-09-23, historicalData: {data: [[Object], [Object] [Object], [Object] [Object], [Object]}} / / omit output

SitesLinkingIn interface

Console.log ("= SitesLinkingIn="); client ({'Action':' SitesLinkingIn', 'Url':' fens.me', 'ResponseGroup':' SitesLinkingIn'}, function (err, data) {if (err) console.log (err); console.log (data);})

Run the program

~ D:\ workspace\ nodejs\ nodejs-alexa > node alexa.js = SitesLinkingIn= {sitesLinkingIn: {site: [[Object], [Object]}}

CategoryBrowse interface

Console.log ("= CategoryBrowse="); client ({'Action':' CategoryBrowse', 'Url':' fens.me', 'Path':' Top/china', 'ResponseGroup':' LanguageCategories'}, function (err, data) {if (err) console.log (err); console.log (data);})

Run the program

~ D:\ workspace\ nodejs\ nodejs-alexa > node alexa.js = CategoryBrowse= {categoryBrowse: {languageCategories:'}} these are all the contents of the article "how to build your own Aleax query service for a website". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report