gpt4 book ai didi

python - 目录中没有该文件

转载 作者:行者123 更新时间:2023-12-01 06:40:43 25 4
gpt4 key购买 nike

我是 Python 新手,我需要传递 URL 列表作为脚本的输入,我使用 f1=open 进行读取,使用 f2=open 进行写入输出

from selenium import webdriver
import selenium
import time
import bs4
import sys



f1=open("links.txt","r")
urls=f1.readlines()
urls=[urls.split()[0] for x in urls]
f1.close()

f2=open("a.txt","w")
for url in urls:
driver = webdriver.Chrome()
driver.get(url)
time.sleep(5)
print(driver.current_url)
f2.write(str(driver.current_url)+"\n")

f2.close()

但是我遇到了这个错误

FileNotFoundError:[Errno 2]没有这样的文件或目录:“links.txt”

请帮助我

最佳答案

FileNotFoundError: [Errno 2] No such file or directory: 'links.txt'

错误提到该文件不存在于目录中。

请注意,您需要检查文件名。我相信您已经通过右键单击新文本文件创建了文本文件,然后将其命名为 links.txt 因此,当您打开文件名时,文件名更改为 links.txt.txt只需按照快照中所述另存为此文件即可。

enter image description here

并尝试以下选项。

f1=open("links.txt","r")

或者您可以不保存为上面提到的文件。

f1=open("links.txt.txt","r")

或者您可以使用文件的完整路径来打开文件。

f1=open(r"D:\Foldername\links.txt.txt","r")

或者

f1=open(r"D:\Foldername\links.txt","r")

请告诉我此解决方法是否适合您。

关于python - 目录中没有该文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59469795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com