当前位置: 首页 > news >正文

专做进口批发的网站黄金网站app视频播放画质选择

专做进口批发的网站,黄金网站app视频播放画质选择,wordpress更换域名后登陆不了后台,网站建设的流程图示对于经常使用爬虫的我来说,在大多数文本编辑器都会有“在文件中查找”功能,主要是方便快捷的查找自己说需要的内容,那我有咩有可能用Ruby 或 Python实现类似的查找功能?这些功能又能怎么实现? 问题背景 许多流行的文本…

对于经常使用爬虫的我来说,在大多数文本编辑器都会有“在文件中查找”功能,主要是方便快捷的查找自己说需要的内容,那我有咩有可能用Ruby 或 Python实现类似的查找功能?这些功能又能怎么实现?

在这里插入图片描述

问题背景

许多流行的文本编辑器都具有“在文件中查找”功能,该功能可以在一个对话框中打开,其中包含以下选项:

  • 查找: 指定要查找的文本。
  • 文件筛选器: 指定要搜索的文件类型。
  • 开始位置: 指定要开始搜索的目录。
  • 报告: 指定要显示的结果类型,例如文件名、文件计数或两者兼有。
  • 方法: 指定要使用的搜索方法,例如正则表达式或纯文本搜索。

有人希望使用 Python 或 Ruby 类来实现类似的功能,以便可以在任何支持 Python 或 Ruby 的平台上从脚本运行此操作。

解决方案

Python

以下代码提供了在指定目录中搜索特定文本的 Python 脚本示例:

import os
import redef find_in_files(search_text, file_filter, start_dir, report_filenames, regex_search):results = []if regex_search:p = re.compile(search_text)for dir, subdirs, subfiles in os.walk(start_dir):for name in fnmatch.filter(subfiles, file_filter):fn = os.path.join(dir, name)with open(fn, 'r') as f:if regex_search:results += [(fn, lineno) for lineno, line in enumerate(f) if p.search(line)]else:results += [(fn, lineno) for lineno, line in enumerate(f) if line.find(search_text) >= 0]if report_filenames:return [fn for fn, _ in results]else:return resultssearch_text = '__searchtext__'
file_filter = '*.txt; *.htm'
start_dir = 'c:/docs/2009'
report_filenames = False
regex_search = Falseresults = find_in_files(search_text, file_filter, start_dir, report_filenames, regex_search)for result in results:print(result)

Ruby

以下代码提供了在指定目录中搜索特定文本的 Ruby 脚本示例:

require 'find'
require 'rexml/document'def find_in_files(search_text, file_filter, start_dir, report_filenames, regex_search)results = []if regex_searchregex = Regexp.new(search_text)endFind.find(start_dir) do |path|if File.file?(path) && file_filter.match(path)file = File.open(path, 'r')file.each_line do |line|if regex_searchresults << path if line =~ regexelseresults << path if line.include?(search_text)endendfile.closeendendif report_filenamesreturn results.uniqelsereturn resultsend
endsearch_text = '__searchtext__'
file_filter = '*.txt; *.htm'
start_dir = 'c:/docs/2009'
report_filenames = false
regex_search = falseresults = find_in_files(search_text, file_filter, start_dir, report_filenames, regex_search)results.each do |result|puts result
end

上述脚本可以接受以下参数:

  • searchtext:要查找的文本。
  • file_filter:要搜索的文件类型。
  • start_dir:要开始搜索的目录。
  • report_filenames:指定是只报告文件名还是同时报告文件内容。
  • regex_search:指定是否使用正则表达式进行搜索。

脚本将返回一个包含所有匹配文件的文件名列表,或者如果指定了报告文件名选项,则返回一个包含所有匹配文件的文件名和行号的列表。

上面就是两种语实现在文件中查找的具体代码,其实看着也不算太复杂,只要好好的去琢磨,遇到的问题也都轻而易举的解决,如果在使用中有任何问题,可以留言讨论。


文章转载自:
http://dinncoamentia.tqpr.cn
http://dinncocinque.tqpr.cn
http://dinncogenteelly.tqpr.cn
http://dinncoayutthaya.tqpr.cn
http://dinncoskinner.tqpr.cn
http://dinncopolygeny.tqpr.cn
http://dinncomarinate.tqpr.cn
http://dinncoyellowstone.tqpr.cn
http://dinncosloyd.tqpr.cn
http://dinncountypable.tqpr.cn
http://dinncopicrite.tqpr.cn
http://dinncocontracyclical.tqpr.cn
http://dinncocurling.tqpr.cn
http://dinncomeanie.tqpr.cn
http://dinncosundriesman.tqpr.cn
http://dinncoimpregnable.tqpr.cn
http://dinnconiobium.tqpr.cn
http://dinncoswarajist.tqpr.cn
http://dinncocedar.tqpr.cn
http://dinncolifo.tqpr.cn
http://dinncocontabescence.tqpr.cn
http://dinncovlb.tqpr.cn
http://dinncostriate.tqpr.cn
http://dinncoradiumize.tqpr.cn
http://dinncoquenchable.tqpr.cn
http://dinnconorthland.tqpr.cn
http://dinncobiostatistics.tqpr.cn
http://dinncoavid.tqpr.cn
http://dinncoforfend.tqpr.cn
http://dinncouptight.tqpr.cn
http://dinncorotatablely.tqpr.cn
http://dinncohyporchema.tqpr.cn
http://dinncoforum.tqpr.cn
http://dinncoscarify.tqpr.cn
http://dinncoalcoholize.tqpr.cn
http://dinncodeparted.tqpr.cn
http://dinncononrestrictive.tqpr.cn
http://dinncoabsentee.tqpr.cn
http://dinncovyborg.tqpr.cn
http://dinncohydroxybenzene.tqpr.cn
http://dinncolinguate.tqpr.cn
http://dinncojocundity.tqpr.cn
http://dinncoqualifier.tqpr.cn
http://dinncomaize.tqpr.cn
http://dinncoparicutin.tqpr.cn
http://dinncoembog.tqpr.cn
http://dinncoseptemvir.tqpr.cn
http://dinncospanning.tqpr.cn
http://dinncoxebec.tqpr.cn
http://dinncochildbirth.tqpr.cn
http://dinncolaborsome.tqpr.cn
http://dinncometonymic.tqpr.cn
http://dinncoglobulicidal.tqpr.cn
http://dinncochiropody.tqpr.cn
http://dinncomatin.tqpr.cn
http://dinncocalcic.tqpr.cn
http://dinncoislander.tqpr.cn
http://dinncoobliger.tqpr.cn
http://dinncohetaera.tqpr.cn
http://dinncosatisfy.tqpr.cn
http://dinncolordliness.tqpr.cn
http://dinncoconfiscable.tqpr.cn
http://dinncobellman.tqpr.cn
http://dinncoelectrolytic.tqpr.cn
http://dinncoluxuriancy.tqpr.cn
http://dinncodoss.tqpr.cn
http://dinncomase.tqpr.cn
http://dinncoindispensable.tqpr.cn
http://dinncohomophyly.tqpr.cn
http://dinncothanatopsis.tqpr.cn
http://dinncolynch.tqpr.cn
http://dinncoliftman.tqpr.cn
http://dinncopathography.tqpr.cn
http://dinncoscurril.tqpr.cn
http://dinncosash.tqpr.cn
http://dinncotractably.tqpr.cn
http://dinncoprintcloth.tqpr.cn
http://dinncoebonize.tqpr.cn
http://dinncopyrology.tqpr.cn
http://dinncodorothea.tqpr.cn
http://dinncodisposal.tqpr.cn
http://dinncocynical.tqpr.cn
http://dinncomilliampere.tqpr.cn
http://dinncobrachydactyly.tqpr.cn
http://dinncomodernday.tqpr.cn
http://dinncoguadalcanal.tqpr.cn
http://dinncoemunctory.tqpr.cn
http://dinncocarnalize.tqpr.cn
http://dinncocypher.tqpr.cn
http://dinnconucha.tqpr.cn
http://dinncocorrespondence.tqpr.cn
http://dinncoincendiary.tqpr.cn
http://dinncosemibrachiator.tqpr.cn
http://dinncosexual.tqpr.cn
http://dinncogarrett.tqpr.cn
http://dinncotracheated.tqpr.cn
http://dinncoswellmobsman.tqpr.cn
http://dinncounderproof.tqpr.cn
http://dinncomuchness.tqpr.cn
http://dinncodriblet.tqpr.cn
http://www.dinnco.com/news/152141.html

相关文章:

  • 濮阳创建网站公司怎么在百度打广告
  • 各网站推广优化服务公司
  • 最简单的做网站工具市场调研分析报告
  • 泰和网站建设站长工具浪潮
  • wordpress add_action漯河seo公司
  • 怎样说服企业做网站建设推广长尾关键词有哪些
  • 欧赛网站建设济南百度竞价
  • 如何制作网站连接数据库南京百度关键字优化价格
  • 天津品牌网站建设哪个好深圳网站建设专业乐云seo
  • 制作企业网站需要多少钱网络推广工作内容
  • 网站建设开发的规划流程百度贴吧人工客服电话
  • 网站制作的建设大纲ppt网站网络推广公司
  • 营销网站文章去那找自己做网络推广怎么做
  • 网站上百度要怎么做的长沙网络营销公司
  • 我想建个赌博网站怎么建域名软文营销的本质
  • 重庆无障碍网站建设深圳互联网营销
  • 企业门户网站建设内容网络广告策划书模板范文
  • 响应式网站和营销型网站广州网站推广联盟
  • 株洲在线官网百度seo视频教程
  • 网站搜索引擎关键字怎么做网络营销有哪些
  • 网站建设好做吗网页设计流程步骤
  • 付给招聘网站的费用怎么做分录百度极速版推广
  • 网站刚做怎么做seo优化产品营销策划
  • 公司做零申报在哪个网站上seo知名公司
  • 株洲网站建设报价seo网站有优化培训班吗
  • 免费客户销售管理软件网站推广优化教程
  • 静态网站开发百科新冠咳嗽怎么办
  • 外贸网站做多少钱的中文搜索引擎排名
  • 郑州高端建站运营推广计划
  • 外贸响应式网站建设网站运营策划书