尝试发送电子邮件时出现python AttributeError

时间:2018-09-17 17:21:13

标签: python python-3.x

此python脚本用于使用匿名者发送电子邮件:

import mechanicalsoup

if __name__ == "__main__":

    URL = "http://anonymouse.org/anonemail.html"
    RECIPIENT = "javaisnotbad@gmail.com"
    SUBJECT = "test python"
    MESSAGE = "salut"

    browser = mechanicalsoup.Browser()

    emailpage = browser.get(URL)

    emailpage.find("input", {"name": "session[To:]"})["value"] = RECIPIENT
    emailpage.find("input", {"name": "session[Subject:]"})["value"] = SUBJECT
    emailpage.find("input", {"name": "session[Message:]"})["value"] = MESSAGE

    browser.submit(emailpage)

运行程序时,出现此错误:

emailpage.find("input", {"name": "session[To:]"})["value"] = RECIPIENT
AttributeError: 'Response' object has no attribute 'find'

如果有人可以帮助,我不明白这个问题。请理解我是一个初学者。

1 个答案:

答案 0 :(得分:0)

必须使用互联网上的模型来重建所有内容:这是固定代码!

import mechanicalsoup

RECIPIENT = "email to send the message to"
SUBJECTT = "the subject" 
MESSAGE = "your message"


browser = mechanicalsoup.StatefulBrowser()

browser.open("http://anonymouse.org/anonemail.html")

#print(browser.get_url())

browser.select_form('form[action="cgi-bin/anon-email.cgi"]')

browser["to"] = RECIPIENT
browser["subject"] = SUBJECTT
browser["text"] = MESSAGE

browser.submit_selected()