emailcontent = []
def getEmails(self):
self.browser.get("https://outlook.live.com/mail/0/inbox")
time.sleep(3)
content = self.browser.find_elements_by_css_selector("._2ZDUqsleGa-jar5wAYvVzV")
for c in content:
c.click() # opens the email
content = self.browser.find_element_by_dir("Itr").text
# div dir="Itr" only common tag for email contents
emailcontent.append(content)
getEmails()
txt = ""
for a in emailcontent:
txt += "{:<30} \n".format(a)
with open("new.txt", "a") as output:
output.write(txt)
os.startfile('new.txt')
我有上面的代码,前面的代码基本上进入了我的hotmail/outlook帐户,没有任何问题。我希望这部分打开每封电子邮件并将内容保存到 txt 文件,但它没有发生。电子邮件内容的唯一常见标签是 div dir="Itr" ,我不知道如何找到_element_...它们一一对应。可能我需要使用循环,但我做不到。有人想帮忙吗?