【发布时间】:2022-01-11 06:10:41
【问题描述】:
每当列表产品的最低价格发生变化时,我都在网上抓取亚马逊并尝试向收件人发送电子邮件。我的代码如下。 j 是 {title:price} 的字典。 title_rating 是 {title:rating} 等的字典。
def create_message():
message = f""
for title in j:
#print(title)
cr_price = j[title]
cr_rating = title_rating[title]
cr_reviews = title_num_reviews[title]
cr_avail = title_avail[title]
str1 = f"Product Title = {title}\n"
str2 = f"{str1}Product Price = {cr_price}\n"
str3 = f"{str2}Product Rating = {cr_rating}\n"
str4 = f"{str3}Number of Product Reviews = {cr_reviews}\n"
str5 = f"{str4}Availability = {cr_avail}\n\n"
message += str5 #str1 + str2 + str3 + str4 + str5
print("message sent")
return message
def send_email(message, sender_email, sender_password, receiver_email):
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login(sender_email, sender_password)
s.sendmail(sender_email, receiver_email, message)
s.quit()
【问题讨论】:
-
@0x263A 是的,确实如此。不过我选择了不同的路线。