AttributeError: 'WebDriver' object has no attribute 'find_elements_by_class'
ikerforce opened this issue · 1 comments
ikerforce commented
After running this snippet,
from bing_images import bing
bing.download_images("cat",
2,
output_dir="/path/to/imgs",
pool_size=10,
file_type="png",
force_replace=True,
extra_query_params='&first=1')
I get the following error:
Save path: /path/to/imgs
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [2], in <cell line: 3>()
1 from bing_images import bing
----> 3 bing.download_images("cat",
4 2,
5 output_dir="/path/to/imgs",
6 pool_size=10,
7 file_type="png",
8 force_replace=True,
9 extra_query_params='&first=1')
File ~/anaconda3/envs/real_meal/lib/python3.10/site-packages/bing_images/bing.py:60, in download_images(query, limit, output_dir, pool_size, file_type, filters, force_replace, extra_query_params)
58 # Fetch more image URLs to avoid some images are invalid.
59 max_number = math.ceil(limit*1.5)
---> 60 urls = fetch_image_urls(query, max_number, file_type, filters, extra_query_params=extra_query_params)
61 entries = get_image_entries(urls, image_dir)
63 print("Downloading images")
File ~/anaconda3/envs/real_meal/lib/python3.10/site-packages/bing_images/bing.py:29, in fetch_image_urls(query, limit, file_type, filters, extra_query_params)
27 if len(file_type) > 0:
28 keywords = query + " " + file_type
---> 29 urls = crawl_image_urls(keywords, filters, limit, extra_query_params=extra_query_params)
30 for url in urls:
31 if isValidURL(url, file_type) and url not in result:
File ~/anaconda3/envs/real_meal/lib/python3.10/site-packages/bing_images/crawler.py:59, in crawl_image_urls(keywords, filters, max_number, proxy, proxy_type, extra_query_params)
57 driver.set_window_size(1920, 1080)
58 driver.get(query_url)
---> 59 image_urls = image_url_from_webpage(driver, max_number)
60 driver.close()
62 if max_number > len(image_urls):
File ~/anaconda3/envs/real_meal/lib/python3.10/site-packages/bing_images/crawler.py:26, in image_url_from_webpage(driver, max_number)
23 img_count = 0
25 while True:
---> 26 image_elements = driver.find_elements_by_class("iusc")
27 if len(image_elements) > max_number:
28 break
AttributeError: 'WebDriver' object has no attribute 'find_elements_by_class'
I tried changing find_elements_by_class("iusc")
to find_elements("class", "iusc")
on crawler.py
as the former is deprecated, but it did not work, it resulted in new issues.
I'm using version 103.0.5060.114 of Chrome and version ChromeDriver 103.0.5060.53 of Chrome Driver. I tried with other versions unsuccesfully.
Thank you in advance.
pedrojlazevedo commented
Hello.
Looking quickly to the implementation you should be able to do this:
from selenium.webdriver.common.by import By
# change line 27 to
image_elements = driver.find_elements(By.CLASS_NAME, "iusc")
# change line
smb = driver.find_elements(By.CLASS_NAME, "btn_seemore")
Good luck.
I can create a PR if needed.