Spider the Yahoo Catalog

Writing a spider to spider an existing spider's site may seem convoluted, but it can prove useful when you're looking for location-based services. This hack walks through creating a framework for full-site spidering, including additional filters to lessen your load.
In this hack, you'll learn how to write a spider that crawls the Yahoo! group of portals. The choice of Yahoo! was obvious; because it is one of the largest Internet portals in existence, it can serve as an ideal example of how one goes about writing a portal spider.
But before we get to the gory details of code, let's define what exactly a portal spider is. While many may argue with such a classification, I maintain that a portal spider is a script that automatically downloads all documents from a preselected range of URLs found on the portal's site or a group of sites, as is the case with Yahoo!. A portal spider's main job is to walk from one document to another, extract URLs from downloaded HTML, process said URLs, and go to another document, repeating the cycle until it runs out of URLs to visit. Once you create code that describes such basic behavior, you can add additional functionality, turning your general portal spider into a specialized one.
Although writing a script that walks from one Yahoo! page to another sounds simple, it isn't, because there is no general pattern followed by all Yahoo! sites or sections within those sites. Furthermore, Yahoo! is not a single site with a nice link layout that can be described using a simple algorithm and a classic data structure. Instead, it is a collection of well over 30 thematic sites, each with its own document layout, naming conventions, and peculiarities in page design and URL patterns. For example, if you check links to the same directory section on different Yahoo! sites, you will find that some of them begin with http://www.yahoo.com/r, some begin with http://uk.yahoo.com/r/hp/dr, and others begin with http://kr.yahoo.com.

If you try to look for patterns, you will soon find yourself writing long if/ elsif/else sections that are hard to maintain and need to be rewritten every time Yahoo! makes a small change to one of its sites. If you follow that route, you will soon discover that you need to write hundreds of lines of code to describe every kind of behavior you want to build into your spider.

This is particularly frustrating to programmers who expect to write code that uses elegant algorithms and nicely structured data. The hard truth about portals is that you cannot expect elegance and ease of spidering. Instead, prepare yourself for a lot of detective work and writing (and throwing away) chunks of code in a hit-and-miss fashion. Portal spiders are written in an organic, unstructured way, and the only rule you should follow is to keep things simple and add specific functionality only once you have the general behavior working.

Okaywith taxonomy and general advice behind us, we can get to the gist of the matter. The spider in this hack is a relatively simple tool for crawling Yahoo! sites. It makes no assumptions about the layout of the sites; in fact, it makes almost no assumptions whatsoever and can easily be adapted to other portals or even groups of portals. You can use it as a framework for writing specialized spiders.

Save the following code to a file called yspider.pl:


Related Posts:
  • HTC E9 is comeing online Sporting the model number A55, HTC E9 is bound to be a budget friendly version of the  Taiwanese manufacturer's flagship, HTC One M9.  The unannounced device will succeed HTC One E8,  who fulfilled the same … Read More
  • BLU Win HD LTE quietly arrived Microsoft BLU Win HD LTE quietly arrived Microsoft LU Win HD LTE quietly arrived on the shelves of the Microsoft Store. The newcomer is a significantly  updated variant of last year's BLU Win HD.  In addition to 4G LTE … Read More
  • Lenovo new A6000 Plus is a 5-incher Lenovo new A6000 Plus is a 5-incher Lenovo is working on keeping its midrange up-to-date  and has now announced in India the new A6000 Plus  model. As the name suggests, it's not an entirely new device, but an… Read More
  • Sony Android 5.0 Lollipop for Xperia Z serie Sony's  main focus remains on the Xperia Z series.  While most other Android smartphones are getting the Android 5.0 Lollipop update, the owners of Sony Xperia devices inquired about the same for  their d… Read More
  • BlackBerry Classic at $430 Indonesia BlackBerry has formally introduced the  BlackBerry Classic in one of its key market - Indonesia. The new BlackBerry Classic has  a full physical QWERTY keyboard along with  the touchscreen display. BlackB… Read More
  • LG rolled out the Android 5.0 LG rolled out the Android 5.0 Lollipop update for  the G2 smartphone in South Korea back in mid-January. After a long wait, the Indian owners  of G2 finally get a word on Lollipop update - expect it in Q2 of 20… Read More
  • Hutchison Whampoa Hutchison Whampoa began talks with  Telefonica to buy carrier O2 UK in January.  The companies have finally reached an agreement  for a sum of £10.3 billion, of course pending an  approval from regul… Read More
  • Google Nexus 4 getting the Android 5.1 Lollipop  Google Nexus 4 getting the Android 5.1 Lollipop Google Nexus 4 smartphone released back in November 2012 will be happy to know that Google  continues to shower updates for it. The Nexus 4 device  owners… Read More
  • Dell Venue 10 7000 The iPad made waves in the business world years ago, its rivals have spent countless hours and dollars on sprucing up their slates to make them worthy of companies' BYOD, or Bring Your Own Device, plans. Dell is one of th… Read More
  • The Microsoft Lumia 640 -Germany, France and UK The Microsoft Lumia 640 and its bigger brother,  the Lumia 640 XL. Only a few days later the former  model has already been put up for pre-order in the  Microsoft store for Germany, France and UK. There … Read More
  • HTC announces the M9+, E9+ HTC announces the M9+, E9+ HTC has announced three new smartphones  in the Indian market. The first is the very new  HTC One M9+ that was revealed very recently.  The M9+ is the bigger brother of the M9 … Read More
  • Microsoft has announced yet another affordable smartphone Microsoft has announced yet another affordable smartphone Microsoft has announced yet another affordable smartphone  for the IMEA, Italy, and APAC regions at sub $150 price  point before subsidies. The new Mic… Read More
  • Amazon app store amazon app store Amazon.com: Free App of the Day Bundle: Apps & Games Online shopping for Free App of the Day Bundle from a great selection at Apps & Games Store. http://www.amazon.com/b?ie=UTF8&node=10076151011… Read More
  • Xiaomi has wildly expanded its product range Xiaomi has wildly expanded its product range -   starting with smartphones, the fast-growing  company now offers TVs, Android TV boxes,  headphones, battery packs and a fitness tracker. And there are more… Read More
  • Galaxy S4 and Galaxy S5 owners in India Samsung had began rolling out the Android 5.0 Lollipop update for its Galaxy smartphone lineup.  Now the Galaxy S4 and Galaxy S5 owners in  India are getting the Lollipop OTA update. The Exynos powered Galaxy S… Read More