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 有一个帐户)。
关于python - 如何通过bs4传递搜索键并获取结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29074052/