python 自动发送邮件求助
本帖最后由 axwa 于 2021-4-19 08:16 编辑python 自动发送邮件求助
发送的内容为网页内容的xpath提取内容
import smtplib
from smtplib import SMTP_SSL
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
from selenium import webdriver
from lxml import etree
from random import randint
class AutoPlay():
def __init__(self) -> None:
self.driver = webdriver.Chrome()
self.url = 'http://www.baidu.com'
def work(self):
self.driver.get(self.url)
page = self.driver.page_source
e = etree.HTML(page)
ycoo =e.xpath('//*[@id="s-top-left"]/a/text()')
print(ycoo)
if __name__ == '__main__':
auto_play = AutoPlay()
auto_play.work()
auto_play.mail()
第22行改为 self.ycoo =e.xpath('//*[@id="s-top-left"]/a/text()')
第23行改为 print(self.ycoo)
第33行改为 mail_content = self.ycoo
总之就是mail()方法中的ycoo与work()方法中的ycoo不是一个 方法中的变量值是私有的
邮箱部分不懂 也没测试 希望可以帮到你 本帖最后由 axwa 于 2021-4-15 10:23 编辑
轻描淡写永恒 发表于 2021-4-15 10:19
第22行改为 self.ycoo =e.xpath('//*[@id="s-top-left"]/a/text()')
第23行改为 print(self.ycoo)
第3 ...
试了的 不行的 ,谢谢他提示['新闻']
Traceback (most recent call last):
File "C:\Program Files\Python38-32\lib\email\message.py", line 356, in set_charset
cte(self)
TypeError: 'str' object is not callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/untitled/测试/自动发送消息1.0.py", line 68, in <module>
auto_play.mail()
File "C:/Users/Administrator/PycharmProjects/untitled/测试/自动发送消息1.0.py", line 55, in mail
msg.attach(MIMEText(mail_content, 'plain', 'utf-8'))
File "C:\Program Files\Python38-32\lib\email\mime\text.py", line 42, in __init__
self.set_payload(_text, _charset)
File "C:\Program Files\Python38-32\lib\email\message.py", line 321, in set_payload
self.set_charset(charset)
File "C:\Program Files\Python38-32\lib\email\message.py", line 364, in set_charset
payload = payload.encode('ascii', 'surrogateescape')
AttributeError: 'list' object has no attribute 'encode'
Process finished with exit code 1 axwa 发表于 2021-4-15 10:22
试了的 不行的 ,谢谢他提示['新闻']
Traceback (most recent call last):
...
23行 self.cont = ycoo
33行 mail_content = self.cont
其余的就是把你自己的邮箱授权码放上去就行了 四楼是对的 22行返回的是一个列表 39行需要传入的是字符串 阿伟de大长腿 发表于 2021-4-15 10:40
23行 self.cont = ycoo
33行 mail_content = self.cont
好的 了解谢谢了
页:
[1]