I decided to learn Python since I now have more time (due to pandemic) and have been teaching myself Python.
I am trying to scrape tax rates from a site and can get almost everything I need. Below is a snippet of the code that comes out of my Soup variable as well as the relevant piece of Python.
Where I am having difficulty is I am finding the option tag along with the data-alias that is empty (""). However, if you look at the code below there are some data-alias stages that are not empty (see UAE or Great Britain)- they have some countries listed.
I am looking to get the data-url and country name from these as well.
How do I code this to get empty tags and non-empty tags as I am losing some required information?
Thanks, Seth
My code:
import requests
from bs4 import BeautifulSoup
import re
l=[]
r = requests.get("https://taxsummaries.pwc.com/")
c=r.content
soup = BeautifulSoup(c, "html.parser")
all = soup.find_all("option", {"data-alias":""})
Website Information:
<option data-alias="" data-id="c9ddd85e-f3dc-4661-a4cb-8101f4644871" data-url="https://taxsummaries.pwc.com:443/uganda">Uganda</option>
<option data-alias="" data-id="d21e8abe-784c-4617-a90e-5369b49a202f" data-url="https://taxsummaries.pwc.com:443/ukraine">Ukraine</option>
<option data-alias="UAE" data-id="9e3f5e7b-f110-47dd-95d8-3d8160466e4a" data-url="https://taxsummaries.pwc.com:443/united-arab-emirates">United Arab Emirates</option>
<option data-alias="Great Britain
UK
Britain
Whales
Northern Ireland
England" data-id="3c42b2a9-7ed6-4b19-821d-5d78ef6f2b5d" data-url="https://taxsummaries.pwc.com:443/united-kingdom">United Kingdom</option>