Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gzip pages decompressor added #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions src/boilerpipe/extract/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ def __init__(self, extractor='DefaultExtractor', **kwargs):
encoding = connection.headers['content-type'].lower().split('charset=')[-1]
if encoding.lower() == 'text/html':
encoding = chardet.detect(self.data)['encoding']
try:
import gzip
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gzip should only be invoked when we are sure that the data is actually compressed. You may want to check an appropriate header.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nowadays lots and lots of websites are gzip
i added exception "pass" if it's not

import StringIO
data = StringIO.StringIO(self.data)
gzipper = gzip.GzipFile(fileobj=data)
self.data = gzipper.read()
#self.data = gzip.decompress(self.data)
except Exception as inst:
#print inst
pass
try:
self.data = unicode(self.data, encoding)
except NameError:
Expand Down