如何通过 bs4 传递搜索键并获取结果

how to pass search key and get result through bs4

def get_main_page_url("https://malwr.com/analysis/search/", strDestPath, strMD5):

    base_url = 'https://malwr.com/'
    url = 'https://malwr.com/account/login/'

    username = 'myname'
    password = 'pswd'

    session = requests.Session()

    # getting csrf value
    response = session.get(url)
    soup = bs4.BeautifulSoup(response.content)
    form = soup.form
    csrf = form.find('input', attrs={'name': 'csrfmiddlewaretoken'}).get('value')
##    csrf1 = form.find('input', attrs ={'name': 'search'}).get('value')

    # logging in
    data = {
        'username': username,
        'password': password,
        'csrfmiddlewaretoken': csrf
    }

    session.post(url, data=data)

    # getting analysis data
    response = session.get(urlparameter)
    soup = bs4.BeautifulSoup(response.content)
    form = soup.form
    csrf = form.find('input', attrs={'name': 'csrfmiddlewaretoken'}).get('value')
##    csrf1 = form.find('input', attrs ={'name': 'search'}).get('value')

    data = {
        'search': strMD5,
        'csrfmiddlewaretoken': csrf
    }

    session.post(urlparameter, data = data)
    response = session.get(urlparameter)
    soup = bs4.BeautifulSoup(response.content)
    print(soup)
    if(None != soup.find('section', id='file').find('table')('tr')[-1].a):
        link = soup.find('section', id='file').find('table')('tr')[-1].a.get('href')
        link = urljoin(base_url, link)

        webFile = session.get(link)
        filename =link.split('/')[-2]
        filename = arg + filename
        localFile = open(filename, 'wb')
        localFile.write(webFile.content)
        webFile.close()
        localFile.close()

我可以通过搜索 crftoken 登录。然后我试图发送 MD5 以在 malware.com 上搜索,但是我无法获得将发送的 MD5 搜索到页面的页面。

我想搜索我们通过crftoken的MD5。 请让我知道代码有什么问题。

您几乎做对了所有事情。除了您需要将 POST 请求的结果传递给 BeautifulSoup。替换:

session.post(urlparameter, data = data)
response = session.get(urlparameter)

与:

response = session.post(urlparameter, data=data)

为我工作(我在 malwr 有一个帐户)。