#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib;
import urllib2;
import os;
import sys;
import shutil;
def searchVT():
VTMainUrl = 'https://www.virustotal.com/en/#search';
headers = {
'accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'content-type':'application/x-www-form-urlencode',
'referer':'https://www.virustotal.com/',
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36'};
postDict = {'query' : '18092AC0F4F694C60762DC98C9F66BC3',};
postData = urllib.urlencode(postDict);
req = urllib2.Request(VTMainUrl, postData, headers);
try:
respHtml = urllib2.urlopen(req).read();
except urllib2.URLError,e:
if hasattr(e,"reason"):
print "Failed to reach the server"
print "The reason:",e.reason
elif hasattr(e,"code"):
print "The server couldn't fulfill the request"
print "Error code:",e.code
print "Return content:",e.read()
else:
pass #其他异常的处理
file_object = open('thefile.txt', 'w')
file_object.write(respHtml)
file_object.close( )
print respHtml;
return respHtml;
if __name__=="__main__":
searchVT();
最近使用urllib2 urlopen尝试打开VT网页并进行使用MD5查询,但是不知道为什么返回的网页为空,求大神赐教~