|
Search Engine Optimization
One of the repetitive task in Search Engine Optimization is to record the current search situation such as the total indexed file, the average page rank. Google provides webmaster tools for a webmaster to monitor the indexing progress of his website in google. However, if you are not the owner of the website or you just have the right for controlling only some part of the website, you have to do you own search and record the record result in the google. This kind of job may be repeated in a daily basis.
Another common job is to measure the performance of or how well a keyword impress the search engine. This can be done by providing the site's name and the keyword in the search engine.
Automation by robots
A lot of tasks related to Search Engine Optimization (SEO) can be done by robots. There are little number of commercial robot software can be found in the market. Most of the case, SEO experts have to write their own robots. Moreover, most of the programming languages are focusing on providing the general usage and they lack of simple commands for fetching a webpages and retrieving information in that webpage. In most programming language. if you want to fetching a webpage, you have to prepare a lot of things, such as: connection objects, http header information, http state handler, etc.
How to use QueScript to build a robot?
To build a robot using QueScript only requires you to write a program in one to two lines of code. The coding style of QueScript is simple and concise. Before you start, you should have the knowledge of JavaScript and Window Script Host (WSH). The following is a simple example which send a request to google for searching keywords within a website and return the search result count:
To do this, follow the steps below (or run the downloaded example):
Explanation of the code
In most of the case, QueScript can be invoked in a Window Script Hosting File (WSF), which is a file in XML format:
<?xml version="1.0">
<package> <job id="GoogleSearchCount"> <!-- here is your code --> </job> </package> Where the job id attribute is the name of your application. The code is placed between the <job> </job> tag. In order to using the QueScript, insert the <script> tag with the source(src) attribute pointing to the location of QueScript.js:
<?xml version="1.0">
<package> <job id="GoogleSearchCount"> <script language="JScript" src="QueScript.js"></script> <script language="JScript"><![CDATA[ // your code goes here! ]]></script> </job> </package> By adding the following code:
var keywords=(typeof QueScript.Argument[1]=="undefined")? "" : "%20" + QueScript.Argument[1]; QueScript .query( "http://www.google.com/search?hl=en&q=site:" +QueScript.Argument[0] +keywords ).parseContentText( /([\d,]+) (from|result)/g, "searchCount" ).write("Search Count:") .writeArray("searchCount",0) .writeln() .pause(); The first two line of code check if there are two arguments. If there exist the second argument, a encrypted space "%20" will be appended before the second argument and store it as the variable "keyword"
var keywords=(typeof QueScript.Argument[1]=="undefined")?
"" : "%20" + QueScript.Argument[1]; The QueScript.query() command access the resource as specified in the bracket of the query(). The resources is a string construction by the protocol name (in this case "http://") and the query information (in this case, it is a url "www.google.com/search?hl=en&q=site:...")
QueScript .query( "http://www.google.com/search?hl=en&q=site:" +QueScript.Argument[0] +keywords ) We uses the parseContentText() method to extract the specific content (parseContentText() ignore all the html tag and just retrieve plain text). Here we use a regular expression stating that we want to extract numbers with comma which followed by either the word "from" or "result". The extracted "numbers with comma" will be stored in an array called "searchCount"
.parseContentText(
/([\d,]+) (from|result)/g, "searchCount" ) Next, we want to display the result we obtained. We use .write() method to display a string "Search Count:" without a "newline" character. Just after that, we want to display the first element in the array "searchCount".
.write("Search Count:")
.writeArray("searchCount",0) We display a newline by using the .writeln() method:
.writeln()
We request the user to press enter before exit from the program:
.pause();
|




