Live data from Hacker News

How to write a crawler

emanueleminotto.it

21–30 of 35 posts

Re: How to write a crawler

#21

Udacity CS101 [1] also goes through the basics of building a web crawler. It's a lot more lightweight (no backend, etc), but it's a fun overview and can be completed pretty quickly. [1]: https://www.udacity.com/course/cs101

I took this when it first came out, definitely a good course for beginners or intermediates.

Re: How to write a crawler

#23
Are you using MySQL in your example?

  > id is an incremental value, I choose 11 as a length 
  for this primary key but this value is defined 
  by the number of pages you’ll need to index
This is a bit confusing. You'd generally be better off with INT UNSIGNED as it doubles the range for auto-increment columns.

Also the visited field would be better to be represented by a timestamp, choosing the right datatype does matter in large tables.

Re: How to write a crawler

#25

I wanna mention Nutch here: http://nutch.apache.org/ since it has been around for a while and a lot of thought was put into its design. For instance, people are discussing data stores, Nutch uses Hadoop. The web is probably bigger than you think, Google says "when our systems that process links on the web to find new content hit a milestone: 1 trillion (as in 1,000,000,000,000) unique URLs on the web at once!" (July,…

1 trillion in 2008.... while not that long ago I wouldn't be surprised if this has exploded since then.

Any numbers?

Re: How to write a crawler

#26
post #19
post #2

I respectfullly disagree. If ever there was a use-case for a NoSQL storage solution, web crawling certainly seems to be it. I've used Elasticsearch for indexing and Cassandra for storage, performance was more than good enough for our use-cases. It was easy to scale, as well.

why do you need Cassandra? isn't it possible to use different storage engines for ES? (disk + memory)

I was storing a lot of raw data (the content of the page crawled, PDF files) and there's no real gain to keeping it inside of the index.

Re: How to write a crawler

#27
post #8
post #5

You definitely want to store raw text in flat files and store metadata in a database. By metadata I'm not referring to only the values found in the html page's meta tags but other things like page hash, word count, link count, etc. It all depends on what you are doing. If it's in a database you will have a very very big file for that archives table (mongodb and mysql+innodb come to mind).

in a couple of projects I worked on, we also stored visited urls in a set of bloom filters, also stored in flat files on disk. At some point querying the db to check what URLs you have can become quite heavy

[deleted]

Re: How to write a crawler

#28
post #5

You definitely want to store raw text in flat files and store metadata in a database. By metadata I'm not referring to only the values found in the html page's meta tags but other things like page hash, word count, link count, etc. It all depends on what you are doing. If it's in a database you will have a very very big file for that archives table (mongodb and mysql+innodb come to mind).

What would a filesystem do better than a DB in that case? After all a filesystem is just a database who's primary keys are mostly filenames.

Most of them use the same data-structures (e.g. b+trees) and especially the newer ones turn into copy-on-write systems like e.g. CouchDB

I guess if you want to have backups of that table, you probably would like to keep it at a manageable size, but why not just save the html blobs in a separate table?

Re: How to write a crawler

#29
post #11

The only complicated part that I've run into when writing crawlers is accidental tarpits. It's very easy to run into a situation in which you're repeatedly requesting the same content via many different URLs. For example, when a tracking parameter is added to any URL within the site: http://example.com/?cid=104484&pid=12002348&ref=1294902 http://example.com/?cid=104484&pid=12002348&ref=1294904 http://example.com/?cid…

If it's not included in robots.txt rules and doesn't have a canonical link that's not a problem, because the bot can't know if those pages are different or not so those pages you linked are different. This is the reason why crawlers can't try to fill forms. If you are really sure that these pages are the same, try checking the body content (if two or more pages have the same MD5 of the content, those pages are the sa…

great tip on the md5, thanks

Re: How to write a crawler

#30

I wanna mention Nutch here: http://nutch.apache.org/ since it has been around for a while and a lot of thought was put into its design. For instance, people are discussing data stores, Nutch uses Hadoop. The web is probably bigger than you think, Google says "when our systems that process links on the web to find new content hit a milestone: 1 trillion (as in 1,000,000,000,000) unique URLs on the web at once!" (July,…

I used to be on the Google indexing team. Disregarding limits on the length of URLs, the size of the visible web is already infinite. For instance, there are many calendar pages out there that will happily give you month after month ad infinitum if you keep following the "next" link.

Now, depending on how you prune your crawl to get rid of "uninteresting" content (such as infinite calendars) and how you deduplicate the pages you find, you'll come up with vastly varying estimates of how big the visible web is.

Edit: on a side note, don't crawl the web using a naive depth-first search. You'll get stuck in some uninteresting infinitely deep branch of the web.

Post reply on HN