Friday, January 10, 2014

Scrap content from web pages

Scraping web content is rewarding - you get the contents you need and at the same time you touch up the technical skills. One of our earlier blog is on downloading a list of MP3 files. This blog was based on an interesting blog by Stu on scraping the list of word-press plugins from web pages. Stu has created many creative scripts even with the limitations posed by the loadrunner and this is not the first time I am inspired by his blogs!

Things have changed a lot since Stu wrote his blog 3 years ago. Here is the structure of a plugin block in the web page as of now. The only fields that can be scrapped are plugin-name, version, last-updated-date, Downloads and stars.

Why is the NetGend script so short? If you compare it to the loadrunner script, you will see that NetGend script doesn't extract values by left/right boundary method. That method may be convenient but it's error-prone. Instead it

Uses xpath to extract an array of HTML blocks for plugins by the function "fromHtml" , each of the HTML blocks will be a XML message,

parses the XML message using the function "fromXml" and accesses the fields.

It's true that the part //div[@class="plugin-block"] requires a little more knowledge such as xpath, however, accessing fields of a XML message is actually straight forward, take c.div.h3.a.value as an example, "c" is the variable name, the part "div.h3.a" follows the structure of the HTML block in an obvious manner. You add "value" at the end of expression to get the value of the field.

Note that NetGend script is immune to changes in HTML tags - adding extra spaces or adding more tags will not affect the script. The same can't be said on the left/right boundary method.

By the way, for someone who truly want to extract values by left-boundary and right-boundary, we do have it supported on NetGend platform.

Scraping content from a web site may or may not generate a lot of web traffic, but it definitely gives a good clue on how flexible the performance test platform is.