国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python實(shí)現(xiàn)E-Mail收集插件實(shí)例教程

2020-02-16 01:04:35
字體:
供稿:網(wǎng)友

__import__函數(shù)

我們都知道import是導(dǎo)入模塊的,但是其實(shí)import實(shí)際上是使用builtin函數(shù)import來工作的。在一些程序中,我們可以動(dòng)態(tài)去調(diào)用函數(shù),如果我們知道模塊的名稱(字符串)的時(shí)候,我們可以很方便的使用動(dòng)態(tài)調(diào)用

def getfunctionbyname(module_name, function_name): module = __import__(module_name) return getattr(module, function_name)

通過這段代碼,我們就可以簡單調(diào)用一個(gè)模塊的函數(shù)了

插件系統(tǒng)開發(fā)流程

一個(gè)插件系統(tǒng)運(yùn)轉(zhuǎn)工作,主要進(jìn)行以下幾個(gè)方面的操作

獲取插件,通過對一個(gè)目錄里的.py文件掃描得到 將插件目錄加入到環(huán)境變量sys.path 爬蟲將掃描好的 URL 和網(wǎng)頁源碼傳遞給插件 插件工作,工作完畢后將主動(dòng)權(quán)還給掃描器

插件系統(tǒng)代碼

在lib/core/plugin.py中創(chuàng)建一個(gè)spiderplus類,實(shí)現(xiàn)滿足我們要求的代碼

# __author__ = 'mathor'import osimport sysclass spiderplus(object): def __init__(self, plugin, disallow = []):  self.dir_exploit = []  self.disallow = ['__init__']  self.disallow.extend(disallow)  self.plugin = os.getcwd() + '/' + plugin  sys.path.append(plugin)  def list_plusg(self):  def filter_func(file):   if not file.endswith('.py'):    return False   for disfile in self.disallow:    if disfile in file:     return False   return True  dir_exploit = filter(filter_func, os.listdir(self.plugin)  return list(dir_exploit)   def work(self, url, html):  for _plugin in self.list_plusg():   try:    m = __import__(_plugin.split('.')[0])    spider = getattr(m, 'spider')    p = spider()    s = p.run(url, html)   except Exception as e:    print (e)

work函數(shù)中需要傳遞 url,html,這個(gè)就是我們掃描器傳給插件系統(tǒng)的,通過代碼

spider = getattr(m, 'spider')p = spider()s = p.run(url, html)

我們定義插件必須使用class spider中的run方法調(diào)用

掃描器中調(diào)用插件

我們主要用爬蟲調(diào)用插件,因?yàn)椴寮枰獋鬟f url 和網(wǎng)頁源碼這兩個(gè)參數(shù),所以我們在爬蟲獲取到這兩個(gè)的地方加入插件系統(tǒng)代碼即可

首先打開Spider.py,在Spider.py文件開頭加上

from lib.core import plugin

然后在文件的末尾加上


disallow = ['sqlcheck']_plugin = plugin.spiderplus('script', disallow)_plugin.work(_str['url'], _str['html'])

disallow是不允許的插件列表,為了方便測試,我們可以把 sqlcheck 填上

SQL 注入融入插件系統(tǒng)

其實(shí)非常簡單,只需要修改script/sqlcheck.py為下面即可

關(guān)于Download模塊,其實(shí)就是Downloader模塊,把Downloader.py復(fù)制一份命名為Download.py就行

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 兰坪| 新泰市| 璧山县| 玉树县| 闽侯县| 清原| 霍山县| 泾阳县| 浪卡子县| 海安县| 元谋县| 博客| 齐河县| 水城县| 湘潭市| 从化市| 察哈| 四川省| 五家渠市| 布拖县| 嫩江县| 临江市| 宁安市| 大关县| 姚安县| 乌兰县| 宝山区| 峡江县| 兰考县| 武山县| 商河县| 道孚县| 宜良县| 枣阳市| 德安县| 张家港市| 墨玉县| 鄂尔多斯市| 岚皋县| 花莲市| 富锦市|