我不久前编写了这个脚本,它将搜索 searchs.txt 文件中所有单词的定义,它用于学校词汇项目。随着新学年的开始,我需要恢复它才能再次使用它。我遇到了奇怪的错误,看起来像是我的 python 安装的问题,但在其他 py 程序中我没有得到任何类似的错误,我可能也没有安装库。代码和错误如下,让我知道您认为问题是什么。提前致谢!代码from subprocess import callimport reimport syslinks = []filename = 'C:\\Users\\TestoW\\Documents\\Coding\\definition-search\\searches.txt'try: with open(filename) as linkListFile: for line in linkListFile: link = line.strip() if link != '': if re.match('http://.+|https://.+|ftp://.+|file://.+', link.lower()): links.append(link) else: links.append('https://www.dictionary.com/browse/' + link) #https://www.google.com/search?q= #https://www.dictionary.com/browse/ #http://maps.google.com/?q=except IOError: print ('Failed to open the file "%s".\nExiting.') sys.exit()print (links)call(["open"]+links)seaches.txt 示例MatterEnergyTemperatureNon-Newtonian Liquid SublimationDeposition窗口错误['https://www.dictionary.com/browse/Matter', 'https://www.dictionary.com/browse/Energy', 'https://www.dictionary.com/browse/Temperature', 'https://www.dictionary.com/browse/Non-Newtonian Liquid', 'https://www.dictionary.com/browse/Sublimation', 'https://www.dictionary.com/browse/Deposition', 'https://www.dictionary.com/browse/Melting Point', 'https://www.dictionary.com/browse/Boiling Point', 'https://www.dictionary.com/browse/Phase Change', 'https://www.dictionary.com/browse/Endothermic', 'https://www.dictionary.com/browse/Exothermic', 'https://www.dictionary.com/browse/Compound', 'https://www.dictionary.com/browse/Intrinsic Property', 'https://www.dictionary.com/browse/Extrinsic Property', 'https://www.diction
1 回答
温温酱
TA贡献1752条经验 获得超4个赞
此代码适用于我打开列表中的链接:
for lnk in links:
call(["start"]+[lnk], shell=True)
- 更新 -
找到了另一种无需打开 cmd 窗口即可打开链接的方法。
import win32com.client
sh = win32com.client.Dispatch('WScript.Shell')
for lnk in links:
sh.run(lnk)
添加回答
举报
0/150
提交
取消