diff --git a/SimpleWebpageParser/README.md b/SimpleWebpageParser/README.md new file mode 100644 index 0000000..13bf4b2 --- /dev/null +++ b/SimpleWebpageParser/README.md @@ -0,0 +1,11 @@ +# Simple Webpage Parser +A simple wrapper around the popular web scraper library BeautifulSoap. It merges the use of Requests and BeautifulSoap library in one class which abstracts the process of extraction of html from webpage's url and gives user a clean code to work with. + +## Libraries Required +1. requests +`$pip install requests` +2. beautifulsoup4 +`$pip install beautifulsoup4` + +## Usage +A sample script `webpage_parser.py` has been provided to show the usage of the SimpleWebpageParser. It prints all the links from the Hacktoberfest's home page. \ No newline at end of file diff --git a/SimpleWebpageParser/SimpleWebpageParser.py b/SimpleWebpageParser/SimpleWebpageParser.py new file mode 100644 index 0000000..30bc38b --- /dev/null +++ b/SimpleWebpageParser/SimpleWebpageParser.py @@ -0,0 +1,13 @@ +import requests +from bs4 import BeautifulSoup + +class SimpleWebpageParser(): + + def __init__(self, url): + self.url = url + + def getHTML(self): + r = requests.get(self.url) + data = r.text + soup = BeautifulSoup(data,"lxml") + return soup \ No newline at end of file diff --git a/SimpleWebpageParser/__init__.py b/SimpleWebpageParser/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/SimpleWebpageParser/webpage_parser.py b/SimpleWebpageParser/webpage_parser.py new file mode 100644 index 0000000..b0fb40a --- /dev/null +++ b/SimpleWebpageParser/webpage_parser.py @@ -0,0 +1,8 @@ +from SimpleWebpageParser import SimpleWebpageParser + +swp = SimpleWebpageParser("https://hacktoberfest.digitalocean.com/") +html = swp.getHTML() +print html.find_all('a') + +## the html returned is an object of type BeatifulSoup, you can parse using BeautifulSoup syntax +## refer to its documentation for more functionalities \ No newline at end of file