Skip to content

Commit ee6c8e9

Browse files
author
xiaoqi.wang
committed
fix compatible with python3
1 parent d117f0d commit ee6c8e9

File tree

9 files changed

+2033
-97
lines changed

9 files changed

+2033
-97
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
/dist
44
*.egg-info
55
*.swp
6+
.python-version
7+
.idea/

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ language: python
22
python:
33
- "2.6"
44
- "2.7"
5-
install: "pip install lxml BeautifulSoup4 requests"
5+
- "3.5"
6+
- "3.6"
7+
install: "pip install -r requirements.txt"
68
script:
79
- python test/test.py

README.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ The basic idea is to insert all css/javascript files into html directly, and use
1414
Save web page directly from url (**recommended** way):
1515

1616
```bash
17-
$ python2 webpage2html.py http://www.google.com > google.html
17+
$ python webpage2html.py https://www.google.com > google.html
1818
```
1919

2020
or save web page first using browsers such as Chrome, to something.html with something_files directory beside.
2121

2222
```bash
23-
$ python2 webpage2html.py /path/to/something.html > something_single.html
23+
$ python webpage2html.py /path/to/something.html > something_single.html
2424
```
2525

2626
But note that the second method may not always work as expected, because there may be urls like `//ssl.gstatic.com/gb/images/v1_c69d5271.png` (from google index page), but the file is missing in `Google_files` directory saved by browsers.
2727

2828
Enable javascript, for example, save 2048 game page into a single html for offline playing
2929

3030
```bash
31-
$ python2 webpage2html.py -s http://gabrielecirulli.github.io/2048/ > 2048.html
31+
$ python webpage2html.py -s http://gabrielecirulli.github.io/2048/ > 2048.html
3232
```
3333

3434
## Dependency

setup.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#!/usr/bin/env python2
2-
31
from distutils.core import setup
4-
from setuptools import find_packages
52

63
setup(
74
name='webpage2html',
@@ -14,19 +11,19 @@
1411
license='LICENSE.txt',
1512
keywords="webpage html convert",
1613
description='Save/convert web pages to a single editable html file',
17-
long_description=open('README.txt').read(),
14+
long_description=open('readme.md').read(),
1815

19-
py_modules = ['webpage2html'],
16+
py_modules=['webpage2html'],
2017

2118
# Refers to test/test.py
2219
test_suite='test.test',
2320

24-
entry_points = {
21+
entry_points={
2522
'console_scripts': [
2623
'webpage2html=webpage2html:main'
2724
]
2825
},
29-
classifiers = [
26+
classifiers=[
3027
'Development Status :: 5 - Production/Stable',
3128
'Environment :: Console',
3229
'Intended Audience :: Developers',
@@ -35,6 +32,8 @@
3532
'Programming Language :: Python',
3633
'Programming Language :: Python :: 2.6',
3734
'Programming Language :: Python :: 2.7',
35+
'Programming Language :: Python :: 3.5',
36+
'Programming Language :: Python :: 3.6',
3837
'Topic :: Software Development',
3938
'Topic :: System',
4039
'Topic :: Terminals',

test/test.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,61 @@
1-
#!/usr/bin/env python2
1+
from __future__ import print_function
2+
3+
import os
4+
import sys
5+
import unittest
26

3-
import os, sys, unittest
47
import webpage2html
58

6-
class Test(unittest.TestCase):
79

10+
class Test(unittest.TestCase):
811
def test_none(self):
9-
print ''
12+
print('')
1013
self.assertEqual(webpage2html.generate('non-existing-file.html', comment=False, verbose=False), '')
1114

1215
def test_pre_formatting(self):
13-
print ''
16+
print('')
1417
gen = webpage2html.generate('./test_pre_formatting.html', comment=False)
1518
assert '<pre><code>$ git clone https://github.com/chaitin/sqlchop</code></pre>' in gen
1619

1720
def test_0ops(self):
18-
print ''
21+
print('')
1922
gen = webpage2html.generate('./hacklu-ctf-2013-exp400-wannable-0ops.html', comment=False)
20-
print gen
23+
print(gen)
2124
assert '<style data-href="./hacklu-ctf-2013-exp400-wannable-0ops_files/screen.css" media="screen, projection" rel="stylesheet" type="text/css">html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt' in gen
2225

2326
def test_no_script(self):
24-
print ''
27+
print('')
2528
gen = webpage2html.generate('./test_no_script.html', comment=False, keep_script=False)
2629
assert '<script' not in gen, gen
2730

2831
def test_full_url(self):
29-
print ''
32+
print('')
3033
gen = webpage2html.generate('./another_dir/test_full_url.html', comment=False, full_url=True)
3134
assert 'href="another_dir/questions/110240"' in gen or 'href="./another_dir/questions/110240"' in gen, gen
3235
assert 'href="another_dir/static/img/favicon.ico"' in gen or 'href="./another_dir/static/img/favicon.ico"' in gen, gen
3336

3437
def test_web_font(self):
35-
print ''
38+
print('')
3639
gen = webpage2html.generate('./webfont.html', comment=False, full_url=True)
3740
# FIXME: do not cover all web fonts with hash postfix
38-
assert 'application/x-font-ttf' in gen, gen
41+
assert 'application/x-font-ttf' in gen and 'application/font-woff' in gen, gen
3942

4043
def test_text_css(self):
41-
print ''
44+
print('')
4245
gen = webpage2html.generate('./text_css.html', comment=False, full_url=True)
43-
print gen
4446
assert '<style data-href="./text_css/style.css" rel="stylesheet" type="text/css">@import url(data:text/css;base64,Cmh' in gen
4547

4648
def test_link_media(self):
47-
print ''
49+
print('')
4850
gen = webpage2html.generate('./test_css_screen.html', comment=False, full_url=True)
4951
assert 'media="screen"' in gen
5052

53+
def test_requests_page(self):
54+
print('')
55+
gen = webpage2html.generate('./test_requests_page.html', comment=False, full_url=True)
56+
assert '<div id="searchbox" role="search" style="display: none">' in gen
57+
58+
5159
if __name__ == '__main__':
5260
if os.path.dirname(sys.argv[0]):
5361
os.chdir(os.path.dirname(sys.argv[0]))

0 commit comments

Comments
 (0)