lundi 4 janvier 2021

Python: File Download Permission error [Errno 13]

    from bs4 import BeautifulSoup
import urllib.request
import requests

url = 'https://en.wikisource.org/wiki/Main_Page'
r = requests.get(url)

Soup = BeautifulSoup(r.text, "html5lib")
List = Soup.find("div",class_="enws-mainpage-widget-content", id="enws-mainpage-newtexts-content").find_all('a')
ebooks=[]
i=0
for ebook in List:
    x=ebook.get('title')
    for ch in x:
        if(ch==":"):
            x=""
    if x!="":
        ebooks.append(x)
        i=i+1
        

inputnumber=0
while inputnumber<len(ebooks):
    print(inputnumber+1, " - ", ebooks[inputnumber])
    inputnumber=inputnumber+1
input=int(input("Please select a book: "))
selectedbook = Soup.find("a", title=ebooks[input-1])
print(selectedbook['title'])
url1 = "https://en.wikisource.org/"+selectedbook['href']
urllib.request.urlretrieve(url1, "C:/Users/Özdal/Desktop/homework")

Here is my code. I'm trying to download the html code of the selected book from user but I get this error when I run the code:

Traceback (most recent call last):
  File "homework.py", line 30, in <module>
    urllib.request.urlretrieve(url1, "C:/Users/Özdal/Desktop/homework")
  File "C:\Users\Özdal\AppData\Local\Programs\Python\Python38-32\lib\urllib\request.py", line 257, in urlretrieve
    tfp = open(filename, 'wb')
PermissionError: [Errno 13] Permission denied: 'C:/Users/Özdal/Desktop/homework'

Where am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire