Created
December 11, 2022 19:10
-
-
Save TheHarold/c362153d06d0039e19d971d217aa4bbc to your computer and use it in GitHub Desktop.
Python3 program to print all li (HTML List items element) tag values for a supplied website
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python3 program to print all li tag values for a supplied website | |
import requests | |
import argparse | |
from bs4 import BeautifulSoup | |
print(help) | |
parser = argparse.ArgumentParser(description='This is a program to print all li tags') | |
parser.add_argument("-url", help="enter the URL you want to parse. eg. https://www.mirraw.com/") | |
args=parser.parse_args() | |
if args.url: | |
url = args.url | |
else: | |
url = input('Enter the URL for which you want all li tag value printed: ') | |
def get_html (url): | |
reqs = requests.get(url) | |
return reqs | |
def find_all_li(reqs): | |
soup = BeautifulSoup(reqs.text, 'lxml') | |
print("\nFind and print all li tags:\n") | |
for tag in soup.find_all("li"): | |
#print("{0}: {1}".format(tag.name, tag.text)) | |
print("{1}".format(tag.name, tag.text)) | |
find_all_li(get_html(url)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You might have to install pip3 install lxml package