栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python调用everything批量查找表格中的文件名在磁盘中是否存在

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python调用everything批量查找表格中的文件名在磁盘中是否存在

python调用everything批量查找表格中的文件名在磁盘中是否存在
  • 介绍
  • Everything 配置
  • 使用openpyxl读写文件
    • 读文件
    • 写文件
  • BeautifulSoup的使用
    • 创建 beautifulsoup 对象
    • soup.find_all的用法
  • 完整代码

介绍

Everything的Http服务器提供了网页支持,我们通过解析网页获取查找信息,从而批量处理数据。

Everything 配置

首先需要打开Everthing 的Http服务器配置,只需要启动该配置并记住端口号即可,配置方式:打开everything-工具-选项-Http服务器,无需设置用户名和密码

输入网址:ip+:+端口号,能够打开everthing搜索即可


参考:https://www.voidtools.com/zh-cn/support/everything/http/

使用openpyxl读写文件 读文件
import openpyxl
wb = openpyxl.load_workbook('sample_file.xlsx')

sheet = wb.active

x1 = sheet['A1']

x2 = sheet['A2']

#using cell() function

x3 = sheet.cell(row=3, column=1)

print("The first cell value:", x1.value)

print("The second cell value:", x2.value)

print("The third cell value:", x3.value)
写文件
from openpyxl import load_workbook
wb = load_workbook(r'C:UsersDEVANSH SHARMADesktopdemo.xlsx')

sheet = wb.active

sheet['A1'] = 'Devansh Sharma'

sheet.cell(row=2, column=2).value = 5

wb.save(r'C:UsersDEVANSH SHARMADesktopdemo.xlsx')
BeautifulSoup的使用 创建 beautifulsoup 对象
soup = BeautifulSoup(html,'lxml')  #创建 beautifulsoup 对象
soup.find_all的用法
  1. 查找标签
 soup.find_all('tag')
  1. 查找文本
 soup.find_all(text='text')
  1. 根据id查找
 soup.find_all(id='tag id')
  1. 使用正则
soup.find_all(text=re.compile('your re')), soup.find_all(id=re.compile('your re'))
  1. 指定属性查找标签
soup.find_all('tag', {'id': 'tag id', 'class': 'tag class'})
完整代码
import openpyxl
import requests
from bs4 import BeautifulSoup

ip='localhost'
wb = openpyxl.load_workbook(r"E:zr书籍.xlsx")

sheet = wb.active
try:
    for row in range(2,245):
        title = sheet.cell(row, 1).value   
        lookup = title.find('(')
        title=title[0:lookup] if lookup!=-1 else title
        lookup = title.find('(')
        title=title[0:lookup] if lookup!=-1 else title
        lookup = title.find(':')
        title=title[0:lookup] if lookup!=-1 else title
        lookup = title.find(':')
        title=title[0:lookup] if lookup!=-1 else title
        lookup = title.find('―')
        title=title[0:lookup] if lookup!=-1 else title
        lookup = title.find('—')
        title=title[0:lookup] if lookup!=-1 else title
        lookup = title.find(' ')
        title=title[0:lookup] if lookup!=-1 else title
        #print(title)
        request = requests.get("http://" + ip + "/?search=" + title)
        content = request.text
        #print(content)
        soup = BeautifulSoup(content,'html.parser')
        result=soup.find_all('p',{'class':'numresults'})
        txt = result[0].string
        if(txt[0]=='0'):
            sheet.cell(row, 6).value='wu'
        else:
            sheet.cell(row, 6).value='you'
finally:
    wb.save('E:zr书籍.xlsx')

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/929497.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号