News for hackers. Stuff that matters.
Re:Dead simple Python crawler for extracting structured data... by echochar on Wednesday January 06, 2016 @11:07PM (#10855914)
"No external imports required..."

I convert HTML to CSV regularly (multiple times a day). But I do not use Python; I use C. Actually I use flex to make filters which I compile as static binaries that read from stdin. This is in fact how I read HN. The HTML is converted to CSV and then the CSV is imported into a database.

Prior to using flex I primarily used sed. For many sites I still do; it's faster than having to compile, test, recompile.

If anyone has a website they want in CSV, and need something faster than Python or Ruby, just post the url. I like to think I am reasonably good at this, but I only do it for personal use on sites I'm interested in so who knows. For me HTML conversion to CSV and plain text is an art - I practice it every day.

Re:Dead simple Python crawler for extracting structured data... by catmanjan on Thursday January 07, 2016 @12:02AM (#10856091)
>This is in fact how I read HN.

Out of curiosity, why?

Re:Dead simple Python crawler for extracting structured data... by echochar on Saturday January 09, 2016 @08:34PM (#10873722)
1. Practice with new programming language and database.

2. Turn unstructured, difficult to parse data adorned with HTML, and other window dressing into structured data that is easier to parse.

Re:Dead simple Python crawler for extracting structured data... by random778 on Thursday January 07, 2016 @11:21AM (#10858773)
I'd like to see HN, actually.
Re:Dead simple Python crawler for extracting structured data... by brachi on Wednesday January 06, 2016 @08:27PM (#10855327)
urlparse().netloc, not netlock. Would be nice to clarify is for Python 2, even better to just do it in 3. Maybe not as dead simple for beginners if you use regular expressions.
Re:Dead simple Python crawler for extracting structured data... by blacksqr on Wednesday January 06, 2016 @09:12PM (#10855508)
Uses one weird trick. Ruby users HATE this!
Re:Dead simple Python crawler for extracting structured data... by sethherr on Wednesday January 06, 2016 @08:09PM (#10855235)
This is why I recommend Ruby over Python for web development. The difference between a blog posted code snippet and the wealth of mature, multiple contributor projects like https://github.com/propublica/upton
Re:Dead simple Python crawler for extracting structured data... by brachi on Wednesday January 06, 2016 @08:29PM (#10855333)
Probably you didn't hear of scrapy https://github.com/scrapy/scrapy
Re:Dead simple Python crawler for extracting structured data... by catmanjan on Thursday January 07, 2016 @12:04AM (#10856101)
+1 for scrapy, very easy to set up while remaining powerful enough to actually use!
Re:Dead simple Python crawler for extracting structured data... by simonw on Wednesday January 06, 2016 @08:34PM (#10855349)
Python has an enormous quantity of mature, multiple contributor projects.
Re:Dead simple Python crawler for extracting structured data... by pinewurst on Wednesday January 06, 2016 @09:40PM (#10855608)
Like the very usable Beautiful Soup: http://www.crummy.com/software/BeautifulSoup/
Re:Dead simple Python crawler for extracting structured data... by orf on Wednesday January 06, 2016 @08:25PM (#10855322)
The author has just decided to roll their own half baked script for some reason, there are plenty of libraries to help. Python is good for scraping, I released my own library recently[1] that I think hits a sweet spot but there are many others.

Python and Ruby have their places, I wouldnt say one is clearly better than the other.

1. http://tomforb.es/scraping-websites-with-cyborg

Re:Dead simple Python crawler for extracting structured data... by rangeva on Thursday January 07, 2016 @01:41AM (#10856386)
The script is intended to be a copy/paste script, with no imports and just "Fill in the blanks" parameters. There A LOT of other options that are much better, but require more setup: http://scrapy.org/ https://pypi.python.org/pypi/spider.py
Re:Dead simple Python crawler for extracting structured data... by aerioux on Thursday January 07, 2016 @02:53AM (#10856595)
upvote - python has ridiculously good (sometimes slowish) scraping libraries, unfortunately the author has written a python wrapper over a regex which completely throws any half-sane crawling out the window.

The except: and continues is enough to cause a heartattack

Re:Dead simple Python crawler for extracting structured data... by sethherr on Wednesday January 06, 2016 @11:44PM (#10856036)
I came across as aggressively flamey - but what I intended to communicate was the difference in the communities. In the Ruby community, if somebody posted a really long regex driven scraper, people would ask why it was written and recommend looking at libraries/gems instead of writing your own. In Python, it ends up on the front page of HN.

Ruby's community is very pragmatic and Python's is more scientific. Most people I'm discussing learning programming with are interested in making something, and pragmatism is far better suited to their goals.

e.g. from my perspective, as someone who uses programming as a tool, writing my own scraper is boring (other scrapers work well enough for me). From my friend's perspective, writing a scraper is a fun experiment.