如何通过搜索键,并打通BS4导致 [英] how to pass search key and get result through bs4
本文介绍了如何通过搜索键,并打通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页。
I am able to login by searching crftoken
. Then I am trying to send MD5
to search on malware.com
, however I am not able to get the page that searches the sent MD5 to page.
我要搜索,我们通过 crftoken
传递MD5。
请让我知道什么是错在code。
I want to search the MD5 that we passes through crftoken
.
Please let me know what is the wrong in code.
推荐答案
您所做的几乎一切正常。除非你需要传递 POST的结果
要求 BeautifulSoup
。替换:
You've done almost everything correctly. Except that you need to pass the result of the POST
request to BeautifulSoup
. Replace:
session.post(urlparameter, data = data)
response = session.get(urlparameter)
与
response = session.post(urlparameter, data=data)
为我工作
(我在malwr帐户)。
Worked for me (I had an account at malwr).
这篇关于如何通过搜索键,并打通BS4导致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文