无法自动执行脚本以使用 Python 请求检查 phishcheck.me 处的 url

Can not automate a script to check url at phishcheck.me with Python requests

在此先感谢,我正在尝试自动获取 URL 是否正在使用此页面(这是必须的)phishcheck.me.

的过程

这是我的 python 代码:

import requests
from time import time
import warnings

warnings.simplefilter("ignore")

def main():
    badurl = "google.com"
    user_agent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36"
    user_agent +=" (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
    url = "https://phishcheck.me/submit"
    referer = 'https://phishcheck.me'
    header = {
        'Referer': referer + "/",
        'User-Agent': user_agent,
        "Origin": referer,
        "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        "Accept": "application/json, text/javascript, */*; q=0.01",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "en-US,en;q=0.9,es;q=0.8",
        "Connection": "keep-alive",
        "Host": "phishcheck.me",
        "X-Requested-With": "XMLHttpRequest"
    }

    client = requests.session()
    client.get(referer, verify=False)
    csrftoken = client.cookies['csrftoken']
    session_id = client.cookies['sessionid']

    cookies = {
        'csrftoken': csrftoken,
        '_ga': 'GA1.2.{0}.1517235473'.format(int(time())),
        '_gid': 'GA1.2.{0}.1519059714'.format(int(time())),
        '_gat': '1',
        "sessionid": session_id
    }

    # Try 1
    payload = {
        'csrfmiddlewaretoken': csrftoken,
        'url': badurl,
        'useragent': '0'
    }
    # Try 2
    payload = "csrfmiddlewaretoken={0}&url={1}&useragent=0".format(
        csrftoken, badurl
    )

    r = client.post(url, headers=header, data=payload,
                    cookies=cookies, verify=False)
    return r

print(main().text)
# {"is_success": false}
print(main().cookies)
# <RequestsCookieJar[<Cookie messages="c0fa3b2c4d55aea15b28a734768e681a2680ff7d$[[__json_message404404Malformed URL. Please check your entry and try again.]]" for phishcheck.me/>]>

Cookie 告诉我格式不正确 URL,我不确定如何修复它。

这是关于如何从 phishcheck.me 网页创建请求的屏幕截图。

任何我遗漏的细节,请询问!

您正在将数据发布到 /submit 而不是 /submit/,这导致您出现此错误,因此您必须将 https://phishcheck.me/submit 更改为 https://phishcheck.me/submit/,它将适用于你

这是我使用的代码:

import requests

requests.urllib3.disable_warnings()

url = 'https://phishcheck.me/'

sess = requests.Session()

g = sess.get(url)

DATA = {
    'url': 'http://google.com',  # <- url you scanning
    'useragent': '0',
    'csrfmiddlewaretoken': g.cookies['csrftoken'],
    'recheck': 'True' # <- False if you don't wanna recheck the link again
}


p = sess.post(url + '/submit/', data=DATA)

d = sess.get('https://phishcheck.me/' + str(p.json()['sid']) + '/details')

print(d.text)