Reputation: 65
I am New To Python, I Need to pass a list of URLs as input to the script, I used f1=open
to read and f2=open
for writing output
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()
But i got this erro
FileNotFoundError: [Errno 2] No such file or directory: 'links.txt'
Please Help Me
Upvotes: 1
Views: 623
Reputation: 33384
FileNotFoundError: [Errno 2] No such file or directory: 'links.txt'
The error mentioned that file is not present in the directory.
Please note that you need to check the file name. I believe you have created text file by right click on new text file and then named it as links.txt
therefore when you open the file name changed to links.txt.txt
just save as this file as mentioned in snapshot.
And try below options.
f1=open("links.txt","r")
Or you could do instead of save as the file as mentioned above.
f1=open("links.txt.txt","r")
Or You can use full path of the file to open the file.
f1=open(r"D:\Foldername\links.txt.txt","r")
OR
f1=open(r"D:\Foldername\links.txt","r")
Let me know if this workaround worked for you.
Upvotes: 1