【问题标题】:Being told to DIE with Python Requests (ically.net reading emails)被告知用 Python 请求死掉(ically.net 阅读电子邮件)
【发布时间】:2020-03-15 04:34:47
【问题描述】:

所以我正在尝试抓取我当前的电子邮件,可以通过 (https://ically.net/mail.php) 访问,同时尝试抓取此网站,

headers = {'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36"}
email = "icall3.amfoamfom@mf.net" #just some random email
def readEmail(email):
    s = requests.Session()
    logger.info(f"Using: {email}")
    encodedBytes = base64.b64encode((str(email)).encode("utf-8"))
    base = str(encodedBytes, "utf-8")
    url = f"https://ically.net/#/{base}"

    resp = s.get("https://ically.net/user.php",data={"user":email},headers=headers)
    resp.raise_for_status()
    resp = s.get("https://ically.net/mail.php?unseen=1",data={"unseen":1},headers=headers)
    resp.raise_for_status()
    resp = s.get("https://ically.net/mail.php")
    resp.raise_for_status()
    print(resp.text)


我最终保留了相同的 cookie,因为我没有更改我的电子邮件地址,它应该会显示我最新的电子邮件,但是当我提出这个请求时,我的输出是 DIE。这感觉有点苛刻。无论如何,我想就抓取/查看是否可以改进我正在尝试做的事情寻求帮助。 (我宁愿继续使用 requests 库,而不是使用 bs4 来做我正在做的事情)。

响应标头:

"{'Server': 'nginx', 'Date': 'Sun, 15 Mar 2020 04:44:32 GMT', 'Content-Type': 'text/html; charset=UTF-8', 'Content-Length': '23', 'Connection': 'keep-alive', 'X-Powered-By': 'PHP/7.0.33, PleskLin', 'Expires': 'Thu, 19 Nov 1981 08:52:00 GMT', 'Cache-Control': 'no-store, no-cache, must-revalidate', 'Pragma': 'no-cache', 'Set-Cookie': 'PHPSESSID=f5m6q05nutvkoon1rn432l8ke1; path=/', 'Vary': 'Accept-Encoding', 'Content-Encoding': 'gzip'}
[Finished in 2.4s]"

【问题讨论】:

  • 让我换个说法:不要在评论部分添加数据!
  • 请不要通过破坏您的帖子为他人增加工作量。通过在 Stack Exchange 网络上发帖,您已在 CC BY-SA 4.0 license 下授予 Stack Exchange 分发该内容的不可撤销的权利(即无论您未来的选择如何)。根据 Stack Exchange 政策,帖子的非破坏版本是分发的版本。因此,任何破坏行为都将被撤销。如果您想了解更多关于删除帖子的信息,请参阅:How does deleting work?

标签: python web-scraping python-requests


【解决方案1】:

URL 只是一个空页面,您的代码没有任何问题。

您是否尝试过使用https://ically.net/#/mail.php 而不是https://ically.net/mail.php

【讨论】:

  • 是的,我有,请随意加载/#/mail.php,它在“加载”网站但没有任何内容的地方做了一些非常奇怪的事情,我尝试过有一个等待计时器但是还是不行。如果您有注册的电子邮件,ically.net/mail.php 实际上有内容,并且还显示最近的电子邮件。
【解决方案2】:

您当前的代码没有指定要查看的任何电子邮件地址,因此有必要做出严厉的回应。

如果您访问 ically.net,打开浏览器的网络检查器并输入电子邮件地址,您会看到有一个 GET 请求,例如https://ically.net/user.php?user=something%40iron.ically.net,后跟https://ically.net/mail.php?unseen=1 请求。

如果您在同一个requests Session 中发出这两个请求(以跟踪 cookie),情况可能会有所不同...

import requests
sess = requests.Session()
# if you like, enable this...
# sess.headers["user-agent"] = "something/something"
resp = sess.get("https://ically.net/user.php", params={"user": "something@iron.ically.net"})
resp.raise_for_status()
resp = sess.get("https://ically.net/mail.php")
resp.raise_for_status()
print(resp.text)

【讨论】:

  • 答:感谢您对会话存储cookies的评论,我不知道它存储cookies。 B:所以我又玩了一些,你是对的,我完全忘记考虑的获取请求,但是我仍然无法阅读最新的邮件消息。另外我假设您的意思是 mail.php,因为没有 email.php。
  • 非常感谢您的回复 :) 仍在试图弄清楚如何阅读这些消息,我可以得到回复但是我的回复只是空的,这让我怀疑我是否读错了。然而,它比得到 DIE 的响应更好。我添加了一个 30 秒的响应,看看它是否只是一个计时器,但它似乎仍然没有阅读它。
猜你喜欢
  • 1970-01-01
  • 2019-04-29
  • 1970-01-01
  • 2021-11-01
  • 1970-01-01
  • 2015-10-20
  • 1970-01-01
  • 2019-05-14
  • 2018-06-21
相关资源
最近更新 更多