Reputation: 373
I am trying to run the following script to get some book data from goodreads.com starting with just a list of titles. I have had this code working recently but am now getting the following error:
Traceback (most recent call last):
File "/home/l/gDrive/AudioBookReviews/WebScraping/GoodreadsScraper.py", line 3, in reload(sys) NameError: name 'reload' is not defined
Here is the Code: https://pastebin.com/Y5NQiVEp
Upvotes: 2
Views: 375
Reputation: 4189
You need to make sure file path exists, and write the file under this directory. Make some modifications of the function create_csv_file()
.
import os
def create_csv_file():
header = ['Title', 'URL']
directory = '/home/l/Downloads/WebScraping'
if not os.path.exists(directory):
os.makedirs(directory)
with open(os.path.join(directory,'GoodReadsBooksNew.csv'), 'w') as csv_file:
wr = csv.writer(csv_file, delimiter=',')
wr.writerow(header)
Upvotes: 0
Reputation: 1833
Lets do a file existence check and access check as follows:
import os
filePathStr = '/home/l/Downloads/WebScraping/GoodReadsBooksNew.csv'
if os.path.isfile():
if os.access(filePathStr, os.R_OK):
print("File exists and is readable")
fileHandle = open(filePathStr, "w+")
else:
print("ERROR: File exists and is NOT readable")
else:
print("Creating output file "+filePathStr)
fileHandle = open(filePathStr, "w+")
Upvotes: 3
Reputation: 301
The error is FileNotFoundError
. Therefore, your python code is not able to find a file in your machine.
Check the path you are providing when calling open
, which is this part of the error message /home/l/Downloads/WebScraping/GoodReadsBooksNew.csv
.
Upvotes: 2
Reputation: 67
as the error states [Errno 2] No such file or directory
Could be permissions or your path is wrong.
Upvotes: 2