我不久前編寫了這個腳本,它將搜索 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
提交
取消