Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include README.rst
include MANIFEST.in
recursive-include tests *.py
prune *.pyc
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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 a 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 after. You can easily write XPATH using the firebug extension, copy XPATH (I recommend edit the XPATH given by firebug, making it shorter).

Installation
============
Expand Down
10 changes: 5 additions & 5 deletions html2data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from lxml import etree
from StringIO import StringIO
from copy import copy

from httplib2 import Http
Expand All @@ -11,8 +10,8 @@ def __init__(self, html = None, url = None, tree = None):
raise Exception('html or url or tree parameters are required')
if url:
connection = Http()
header, html = connection.request(url)
elif html:
_, html = connection.request(url)
if html:
self.tree = self._get_tree_from_html(html)
else:
self.tree = tree
Expand Down Expand Up @@ -55,7 +54,6 @@ def _get_one(elements):
return (elements or [None])[0]

def _apply_after(self, value, apply_after, multiple, strip, text):
total_added_after = 0
if not multiple:
apply_after.insert(0, self._get_one)
if strip and text:
Expand All @@ -66,7 +64,9 @@ def _apply_after(self, value, apply_after, multiple, strip, text):
value = after(value)
return value

def parse_one(self, xpath = None, css = None, multiple = False, apply_after = [], text = True, strip = True):
def parse_one(self, xpath = None, css = None, multiple = False, apply_after = None, text = True, strip = True):
if apply_after is None:
apply_after = []
#TODO: Be able to return elements and text
if xpath:
value = self.xpath(xpath.replace('/text()', ''))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def read(fname):
license = "BSD",
keywords = "html2data html data xpath crawler transform",
url = "https://github.com/dperezrada/html2data",
packages=['html2data', 'tests'],
packages=['html2data', ],
long_description=read('README.rst'),
include_package_data=True,
classifiers=[
Expand Down
1 change: 0 additions & 1 deletion tests/test_parse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: utf-8
import os
from unittest import TestCase


Expand Down
2 changes: 0 additions & 2 deletions tests/test_tree.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# encoding: utf-8
import os
from unittest import TestCase

from httplib2 import Http
from ludibrio import Mock

from html2data import HTML2Data
Expand Down