import requests
from bs4 import BeautifulSoup
import pprint as ppr
import re
#---------------------------------
class Malhash:
# 생성자
def __init__(self):
self.target_url = "https://virusshare.com/hashes.4n6"
"""
https://virusshare.com/hashes/VirusShare_00001.md5
"""
self.subURL = []
self.html = None
self.bsObject = None
self.f = re.compile("^[A-Za-z0-9]")

def hashRequests(self):
self.html = requests.get(self.target_url)
if self.html.status_code == 200:
print ("Requests success")
'''
status code
1.xx
2.xx : success
3.xx
4.xx
5.xx
'''
self.bsObject = BeautifulSoup(self.html.text, "html.parser")
s = self.bsObject.select("body > p > p > table > tr > td > p > a")
'''
body > p:nth-child(3) > table > tbody > tr > td > p:nth-child(1)
body > p:nth-child(3) > table > tbody > tr > td > p:nth-child(1) > a:nth-child(2)
'''
tmp_url = "https://virusshare.com/"
for i in s:
print (i.attrs['href'])
self.subURL.append(tmp_url + i.attrs['href'])
print ("sub_url information ==========================")
ppr.pprint(self.subURL)
'''
https://virusshare.com/hashes/VirusShare_00000.md5
'''
def subhashRequests(self):
for u in self.subURL:
print(u)
h = requests.get(u)
if h.status_code == 200:
print ("요청 성공 url : {}".format(u))
b = BeautifulSoup(h.text, "html.parser").text
b = re.sub(pattern='[\n,\r,\t]', repl='', string=b)
for i in range(0, len(b), 32):
if self.f.search(b[i:i+32]):
textFhash = open("hashValue.text", "a")
textFhash.write(b[i:i+32]+'\n')
textFhash.close()
break
def main():
node = Malhash()
node.hashRequests()
node.subhashRequests()
if __name__ == "__main__":
main()


'언어 > python' 카테고리의 다른 글

python watchdog 공부  (0) 2018.10.20
정규식  (0) 2018.10.16
python winlog event  (0) 2018.10.10
python + 사람인  (0) 2018.10.09
python + 크롤링 + mysql  (0) 2018.10.09