I am trying to search for email in a specific HTML. I want to run the code so that when there is no email found in an element to search in another element in HTML and in the end if it is not found to set email as N/A.
I am new to writing code and I am trying to do it for a training exercise for a project.
Here is what I came up with:
email_list = [] bio = soup.find('div', {'class': 'UserInfo'}).text for my_tag in soup.find_all(class_="UserInfo"): EMAIL_REGEX = "[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+" emails = re.findall(EMAIL_REGEX, my_tag.text) if not my_tag.text: # if tag is empty my_tag.decompose() print(emails)
the outcome that I am receiving when I print(emails)
, if there are no emails present in the for loop, in which I am trying to get rid of:
[] [] []
My questions:
The HTML which I am breaking down has similar classes under the same tag. My issue is that I just want to know how to search from one element with a specific class and if no outcome is found to search in another element with another class and in the end instead of receiving [] [] []
to become N/A
没有评论:
发表评论