From 51a14bfcd0edfb000d466ffc512ae5f61831a3f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Leli=C3=A8vre?= Date: Sun, 10 Feb 2019 00:09:33 +0100 Subject: [PATCH] Fix typos and PEP8 in README Minor typos and PEP8 fixes. --- README.rst | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/README.rst b/README.rst index e5b6471..61ebc3a 100644 --- a/README.rst +++ b/README.rst @@ -7,24 +7,29 @@ Welcome to Html2Data Description =========== -A simple way to transform a HTML file or URL to structured data. You only need to define the xpath to the element. Optionaly you can define functions to be applied after. You can easily write XPATH using the firebug extension, copy XPATH (I recommend edit the XPATH given by firebug, making it shorter). + +A simple way to transform an HTML file or URL to structured data. You only need to define the xpath to the element. Optionally you can define functions to be applied afterwards. You can easily write XPATH using the firebug extension, copy XPATH (I recommend editing the XPATH given by firebug, making it shorter). Installation ============ + :: >> easy_install html2data Example ======= + Import ------ + :: >>> from html2data import HTML2Data Create instance --------------- + :: >>> html = """ @@ -34,14 +39,16 @@ Create instance

Title

-
This is not a valid HTML +
This is not valid HTML """ - >>> h2d_instance = HTML2Data(html = html) #You can also create it from a url = url + >>> h2d_instance = HTML2Data(html=html) # You can also create it from a url = url Using XPATH config -------------------- -One you have the object + +Once you have the object + :: >>> config = [ @@ -50,11 +57,12 @@ One you have the object {'name': 'description', 'xpath': '//div[@class="description"]/text()'}, ] - >>> h2d_instance.parse(config = config) - {'header_title': 'Example Page', 'body_title': 'Title', 'description': 'This is not a valid HTML'} + >>> h2d_instance.parse(config=config) + {'header_title': 'Example Page', 'body_title': 'Title', 'description': 'This is not valid HTML'} Using CSS SELECTOR config ------------------------- + :: >>> config = [ @@ -64,11 +72,12 @@ Using CSS SELECTOR config ] >>> h2d_instance.parse(config = config) - {'header_title': 'Example Page', 'body_title': 'Title', 'description': 'This is not a valid HTML'} + {'header_title': 'Example Page', 'body_title': 'Title', 'description': 'This is not valid HTML'} Real life example ----------------- + :: import urllib2 @@ -85,13 +94,14 @@ Real life example {'name': 'estado', 'css': 'td:nth-child(4)'}, ] - html_instance = HTML2Data(html = html) - rows = html_instance.parse_one(css = 'td td tr', multiple = True, text = False) + html_instance = HTML2Data(html=html) + rows = html_instance.parse_one(css='td td tr', multiple=True, text=False) for row_element in rows[1:]: - row_in_html = HTML2Data(tree = row_element) - print row_in_html.parse(config = config) + row_in_html = HTML2Data(tree=row_element) + print row_in_html.parse(config=config) You will get something like: + :: {'nombre': 'Reforma Constitucional que restablece obligatoriedad del voto.', 'fecha': '24/11/2011', 'estado': 'En tramitación', 'id': '8062-07'} @@ -99,16 +109,17 @@ You will get something like: {'nombre': 'Prohíbe el anatocismo.', 'fecha': '02/11/2011', 'estado': 'En tramitación', 'id': '8007-03'} -Requirement -=========== +Requirements +============ * lxml 2.0+ * httplib2 Tests ===== -Requirement ------------ + +Requirements +------------ * ludibrio * nose @@ -117,4 +128,3 @@ Run --- >> nosetests - \ No newline at end of file