Skip to content

Instantly share code, notes, and snippets.

@TheHarold
Created December 11, 2022 19:10
Show Gist options
  • Save TheHarold/c362153d06d0039e19d971d217aa4bbc to your computer and use it in GitHub Desktop.
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
# 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))
@Lalatenduswain
Copy link

ented Dec 12, 2022

You might have to install pip3 install lxml package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment