I want to send an e-mail by pulling the advertisement links that I have collected from a site one by one. I wrote a system but it doesn't work, it doesn't give an error either. Namely, if there are certain words and phone numbers in the advertisement, it will not send an e-mail, otherwise it will send an e-mail. I did filters. I am sharing my codes. If there are errors you see when you look at them (such as logic, code errors…) I would be very happy if you could share them.
Word Filter
try:
re = driver.find_element(By.XPATH, "/html/body")
search_words = re.findAll(
"Import",
"Tree",
"Seven",
)
print("\nCannot send mail because it contains the word.Index :", i)
print(re.findAll)
except:
search_words = " "
time.sleep(1)
CodePudding user response:
re will return a WebElement. I think you are looking for the text from element? If so, you need to use the (text) property:
re = driver.find_element(By.XPATH, "/html/body").text
But to work properly you can do it like this:
try:
web_text = driver.find_element(By.XPATH, "/html/body").text
words = ["Import", "Tree", "Seven"]
search_words = [word for word in words if re.findall(word, web_text)]
text_words = ''
if search_words:
for i, word in enumerate(search_words):
if i < len(search_words) - 1:
text_words = f"{word}, "
else:
text_words = f"{word}."
print(f"\nCannot send mail because it contains the word.Index : {text_words}")
print(re.findall)
except Exception:
text_words = ""
time.sleep(1)