Skip to main content

An html comparator that can output the differences between html code

Project description

htmlcomparator

This is a light-weight python package used to compare two html files and return the differences.

The users can choose whether they want a boolean result or string result that specify the difference. They can also choose the types of differences they want to receive.

Usage

To start using the comparator, first import the package, and make an object.

from htmlcomparator import HTMLComparator
comparator = HTMLComparator()

The method that is used to compare html code is

comparator.compare(html1, html2, quick_compare = True, compare_type = "all")

html1, html2 are the two html to be compared. If they are both strings, it will treat them as two html strings. If they are both io.IOBase objects, then the program will treat them as two opened files. Otherwise the program will raise a TypeError.

quick_compare argument is used to specify whether the user want the method to simply return boolean or to return a detailed information of the differences. If it is set to True, then the method will return False as soon as it encounters the first difference, and return True if there are no difference. If it is set to False, then the two html are compared thoroughly, and the method will return a string to describe the differences. If there are no differences, it will return an empty string.

compare_type argument is used to specify the type of differences to compare. It is ignored if quick_compare is set to True. If it is set to tag, then only tag differences will be returned. If it is set to data then tag and data differences will be returned. If it is set to all, then all differences will be considered, including tags, data, and attributes.

For example,

s1 = "<!DOCTYPE xml> <head> <p> test </p> <p> different here </p> </head>"
s2 = "<!DOCTYPE html> <head> <p> this is different </p> </head>"
comparator = HTMLComparator()
print(comparator.compare(s1,s2, compare_type = "all", quick_compare = False))

will output:

@@ DOCTYPE Difference @@
*DOCTYPE xml
-DOCTYPE html

extra tag <p> in the first html at (1, 36)

@@ (1, 25) , (1, 26) @@
*test
-this is different

The tuples (1, 36), (1, 25), and (1, 25) give the line number and the offset of the differences.

Limitations

Currently doesn't support CSS.

License

Copyright Mengjia Zhao 2020. Distributed under the terms of the Apache 2.0 license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

htmlcomparator-0.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

htmlcomparator-0.1.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file htmlcomparator-0.1.0.tar.gz.

File metadata

  • Download URL: htmlcomparator-0.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9

File hashes

Hashes for htmlcomparator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 df49a9e5bed128042795de1982dcf486b4d52de68872fd88756f9f2a096677f1
MD5 2f018119258d43132b56c36abe32b3d4
BLAKE2b-256 03ffd7c10373f7bcefcf74ef84708d757e297d349c35190e19a223992beb13a2

See more details on using hashes here.

File details

Details for the file htmlcomparator-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: htmlcomparator-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9

File hashes

Hashes for htmlcomparator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c552afdc2ab2881eeaa0bf693fcb6b35f18a17479b41eb3f988f837dd022d8c
MD5 bea09aaed83c9d05de540f63d169795b
BLAKE2b-256 b723726c190d65b6c1982f4ebb0c7f0b5c909c9cdfd7a946071d550fc5a40a99

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page