py_everything.htmlXml

Source code: py_everything/htmlXml.py

This module deals with HTML/XML Files. This module will be extended in later releases. With functions that fetch tags from document for you to a class allowing all methods in one! This module doesn’t check if the HTML/XML file is valid or not. It will return matches if a certain tag is not closed. This module was added in version 2.0.0

Changed in version 2.3.0: All functions in this module return a tuple (lineNo, line)

class py_everything.htmlXml.HTMLObject(fileName)

This class access to all methods without having to give the fileName everytime.

>>> from py_everything.html import HTMLObject
>>> myHtml = HTMLObject('C:/index.html')
>>> divs = myHtml.getElementsByTag('div')
>>> divs
["<div id='app'>This is main app</div>", "<div>Other part of HTML</div>"]
>>> title = myHtml.getElementByTag('title')
>>> title
['<title>Demo Website</title>']
>>> mainApp = myHtml.getElementById('app)
>>> mainApp
["<div id='app'>This is main app</div>"]
Parameters

fileName (str) – A string containing full path to HTML/XML file.

getElementsByTag(tagName)

Searches HTML/XML file for given tagName.

Parameters

tagName (str) – The tag you want to search for.

Returns tuple

A tuple containg line number and the line in following order - (lineNo, line)

Note

The whole line is returned if a match is found. And the tag is not validated.

getElementsById(idName)

Searches HTML/XML file for given tags with the id of idName.

Parameters

idName (str) – The id you want to search for.

Returns tuple

A tuple containg line number and the line in following order - (lineNo, line)

Note

The whole line is returned if a match is found. And the tag is not validated.

getElementsByClass(className)

Searches HTML/XML file for given tags with the class of className.

Parameters

className (str) – The class you want to search for.

Returns tuple

A tuple containg line number and the line in following order - (lineNo, line)

Note

The whole line is returned if a match is found. And the tag is not validated.

getElementByTag(tagName)

Searches HTML/XML file for given tagName. And returns only the first match.

Parameters

tagName (str) – The tag you want to search for.

Returns list

A list containing first match in str.

Note

The whole line is returned if a match is found. And the tag is not validated.

getElementById(idName)

Searches HTML/XML file for given tags with the id of idName. And returns only the first match.

Parameters

idName (str) – The id you want to search for.

Returns list

A list containing first match in str.

Note

The whole line is returned if a match is found. And the tag is not validated.

getElementByClass(className)

Searches HTML/XML file for given tags with the class of className. And returns only the first match.

Parameters

className (str) – The class you want to search for.

Returns list

A list containing first match in str.

Note

The whole line is returned if a match is found. And the tag is not validated.

py_everything.htmlXml.getElementsByTag(tagName, fileName)

Searches HTML/XML file fileName for given tagName.

Parameters
  • tagName (str) – The tag you want to search for.

  • fileName (str) – A string containing full path to HTML/XML file.

Returns tuple

A tuple containg line number and the line in following order - (lineNo, line)

Note

The whole line is returned if a match is found. And the tag is not validated.

py_everything.htmlXml.getElementsById(idName, fileName)

Searches HTML/XML file fileName for given tags with the id of idName.

Parameters
  • idName (str) – The id you want to search for.

  • fileName (str) – A string containing full path to HTML/XML file.

Returns tuple

A tuple containg line number and the line in following order - (lineNo, line)

Note

The whole line is returned if a match is found. And the tag is not validated.

py_everything.htmlXml.getElementsByClass(className, fileName)

Searches HTML/XML file fileName for given tags with the class of className.

Parameters
  • className (str) – The class you want to search for.

  • fileName (str) – A string containing full path to HTML/XML file.

Returns tuple

A tuple containg line number and the line in following order - (lineNo, line)

Note

The whole line is returned if a match is found. And the tag is not validated.

py_everything.htmlXml.getElementByTag(tagName, fileName)

Searches HTML/XML file fileName for given tagName. And returns only the first match.

Parameters
  • tagName (str) – The tag you want to search for.

  • fileName (str) – A string containing full path to HTML/XML file.

Returns list

A list containing first match in str.

Note

The whole line is returned if a match is found. And the tag is not validated.

py_everything.htmlXml.getElementById(idName, fileName)

Searches HTML/XML file fileName for given tags with the id of idName. And returns only the first match.

Parameters
  • idName (str) – The id you want to search for.

  • fileName (str) – A string containing full path to HTML/XML file.

Returns list

A list containing first match in str.

Note

The whole line is returned if a match is found. And the tag is not validated.

py_everything.htmlXml.getElementByClass(className, fileName)

Searches HTML/XML file fileName for given tags with the class of className. And returns only the first match.

Parameters
  • className (str) – The class you want to search for.

  • fileName (str) – A string containing full path to HTML/XML file.

Returns list

A list containing first match in str.

Note

The whole line is returned if a match is found. And the tag is not validated.