the code runs fine until it tries to access the directory. any input is appreciated thanks
Here is the code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os
import ast
import requests
import urllib.request
from bs4 import BeautifulSoup as Soup
opts = Options()
opts.add_argument("user-agent=chrome/23.0.1271")
driver = webdriver.Chrome("./chromedriver.exe")
url = 'https://s.aolcdn.com/os/ab/_cms/2020/09/09081722/568224.jpg'
directory = 'RAW'
FILETYPE = '.jpg'
r = requests.get(url,allow_redirects=True)
def find_urls(url):
driver.get(url)
wait = input('loading...lmao')
page = driver.page_source
soup = Soup(page,'lxml')
images = soup.find_all('img',{"src":True})
all_images = []
for image in images:
image_src = image['src']
print(image_src)
urllib.request.urlretrieve(image_src)
Images = find_urls(url)
def save_img(Image,directory):
if not os.path.isdir(directory):
os.mkdir(directory)
for i,link in enumerate(url):
path = os.path.join(directory,'(:06).jpg'.format(i))
try:
ulib.urlretrieve(link,path)
except:
print('Failed:')
save_img(Images,directory)
I think might be how I access the directory but I'm running out of things to try I've checked the folder made sure to run as admin.
This error message...
ERROR:process_reader_win.cc(123)] NtOpenThread: {Access Denied}
...implies that the ChromeDriver initiated thread was unable to read the system resource as access was denied.
A common cause for Access Denied is running Chrome as root
user ( administrator
) on Linux. While it is possible to work around this issue by passing --no-sandbox
flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome as a regular user instead.
Ensure that:
@Test
as non-root user.driver.quit()
within tearDown(){}
method to close & destroy the WebDriver and Web Client instances gracefully.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.