Im working on Scrapping News From https://finance.detik.com/indeks. I work on Windows OS with VS code as code editor. Somehow my program can open web browser but can't read WebElement and give error like this :
DevTools listening on ws://127.0.0.1:54867/devtools/browser/ed90b4ff-9d7d-40b5-974b-edfc955e2410 [6384:8844:0925/194226.820:ERROR:device_event_log_impl.cc(214)] [19:42:26.820] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[6384:8844:0925/194226.821:ERROR:device_event_log_impl.cc(214)] [19:42:26.821] Bluetooth: bluetooth_adapter_winrt.cc:713 GetBluetoothAdapterStaticsActivationFactory failed: Class not registered (0x80040154)
this is my code :
from pandas.core.frame import DataFrame
from selenium import webdriver
from time import sleep
driver = webdriver.Chrome("D:\chromedriver.exe")
driver.get("https://finance.detik.com/indeks")
sleep(3)
# The code below usually results in an error WebElement not found
# ---------------------------------------------------------
article = driver.find_elements_by_class_name("just_test")
#----------------------------------------------------------
for i in article:
print(i)
driver.close()
driver.quit()
I've been looking for the solution in Failed to read descriptor from node connection: A device attached to the system is not functioning error using ChromeDriver Selenium on Windows OS but nothing work on me. I hope you guys know the answer.. Thanksss :)
CodePudding user response:
I am not getting the same error as you've got. But I ran the below code in my local.
- Use
find_elements
to list all the article. - Use JS to scroll to each element.
Code :
driver = webdriver.Chrome(driver_path)
driver.maximize_window()
#driver.implicitly_wait(30)
wait = WebDriverWait(driver, 30)
driver.get("https://finance.detik.com/indeks")
time.sleep(3)
size_of_scrapper = len(driver.find_elements(By.XPATH, "//article"))
j = 1
for i in range(size_of_scrapper):
element = driver.find_element_by_xpath(f"(//article)[{j}]")
driver.execute_script("arguments[0].scrollIntoView(true);", element)
inner_value = element.find_element(By.XPATH, ".//descendant::h3/a").get_attribute('innerText')
print(inner_value)
j = j 1
Output :
Generasi Milenial Didorong Terjun ke Dunia Pertanian, Bagaimana Caranya? Catat! Bantuan Subsidi Gaji Rp 1 Juta Tak Kena Potongan Putri Nia Daniaty Tersandung Dugaan Penipuan CPNS, BKN Ingatkan Hal Ini Biar Pariwisata Moncer Lagi, Maskapai-Travel Online Kasih Diskon Nih! Petani Singkong di Lampung Ini Raup Cuan Rp 150 Juta Lho Per Tahun Apa itu Dana Alokasi Khusus yang Bikin Azis Syamsuddin Terjerat KPK? Petani Lampung Raup Omzet Rp 150 Juta per Tahun dari Tanam Singkong Siap-siap! PeduliLindungi Mau Diuji Coba di Pasar Ada yang Baru Naik, Ini Daftar Harga Terbaru BBM Pertamina Kerek Harga, Mendag Mau Serap Telur Peternak buat Bansos Perajin Layangan Naga Panen Cuan Kala Pandemi Melanda 4 Fakta Tol Semarang-Demak Dibangun Pakai Bambu Kemnaker Bahas Hubungan Industrial Pascapenetapan UU Cipta Kerja Jadi Tersangka Kasus Suap, Azis Syamsuddin Punya Gaji Segini Besar Sosok Hui Ka Yan, Buruh Pabrik yang Jadi Pemilik Evergrande Deretan Kantor BUMN yang Mau Dibubarkan, Dari Ruko hingga Gedung Tinggi KAI Gandeng BNPT Cegah Terorisme dan Radikalisme, Begini Caranya Hutama Karya Buka Banyak lowongan, Yang Mau Lamar Perhatikan Hal Ini! Jejak Pengutang BLBI Suyanto Gondokusumo, Pernah Punya Saham CFC Dear Penumpang KRL! Ini Tempat Naik-Turun Baru di Stasiun Manggarai
Process finished with exit code 0
CodePudding user response:
You need to add options in my case I used this to ignore different Bluetooth and USB messages
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--disable-webgl")
options.add_experimental_option("excludeSwitches", ["enable-logging"])
path = r'chromedriver.exe'
driver = webdriver.Chrome(path,options=options)