日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python爬虫脚本ie=utf-8_python脚本-共享文件爬虫

發(fā)布時間:2024/10/8 python 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python爬虫脚本ie=utf-8_python脚本-共享文件爬虫 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

import sqlite3, time

from pathlib import Path

# 搜索共享目錄下的文件并過濾

def apply_dfs(root_path, file_callback, dir_callback):

try:

[x for x in root_path.iterdir()]

except FileNotFoundError:

print("file not found:", root_path)

return

except:

print("something bad happened:", root_path)

return

for x in root_path.iterdir():

if x.is_file():

file_callback(x)

elif x.is_dir():

dir_callback(x)

apply_dfs(x, file_callback, dir_callback)

else:

pass

# 過濾文件格式

def process_file_path(path):

try:

if not path.suffix in acceptable:

return

cursor.execute("insert into shared_files values (?, ?)", \

(path.name, str(path).replace("\\", "/")))

except:

return

def process_dir_path(path):

pass

def format_host(host):

host = str(host)

while len(host) < 3:

host = "0" + host

return host

# main function

conn = sqlite3.connect("share.db")

cursor = conn.cursor()

acceptable = (".txt", ".doc", ".docx", ".ppt", ".pptx", ".xls", ".xlsx", \

".pdf", ".rar", ".zip", ".tar", ".gz", ".bz2", ".xz", ".7z", \

".msg", ".exe", ".msi")

for host in range(445,999):

start = time.time()

p = Path(r"\\hostnameprex" + format_host(host) + "/share")

print("start crawling host:hostnameprex",format_host(host))

apply_dfs(p, process_file_path, process_dir_path)

end = time.time()

print("complete crawling:", format_host(host), \

"elasped time:", end - start, "s")

conn.commit()

conn.close()

查詢腳本:

import sqlite3 as db

import os

#查詢數(shù)據(jù)庫

def query(name):

#創(chuàng)建連接

conn = db.connect("share.db")

#獲取游標

sqlite_cursor = conn.cursor()

sql_select="SELECT * FROM shared_files where filename like ?;"

sqlite_cursor.execute(sql_select,('%'+name+'%',))

for row in sqlite_cursor:

print(row[0]+""+row[1])

conn.close()

# 入口

while True :

keyword = input('please input keyword:')

if keyword != '':

query(keyword)

break

總結(jié)

以上是生活随笔為你收集整理的python爬虫脚本ie=utf-8_python脚本-共享文件爬虫的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。