Added a Simple Webpage Parser

This commit is contained in:
nitish-iiitd 2018-10-10 01:06:59 +05:30
parent b24df42521
commit 7256ad9e86
4 changed files with 32 additions and 0 deletions

View File

@ -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 extracting of html from web url logic 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.

View File

@ -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

View File

View File

@ -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