Home > Back-end >  I want to scrape all the elements from what's app but I'm having problem with selenium pyt
I want to scrape all the elements from what's app but I'm having problem with selenium pyt

Time:10-01

I want to scrape all the elements from what's app but I'm having problem with selenium python This is my code :

from selenium import webdriver
from selenium.webdriver.common import keys
import time

driver = webdriver.Chrome("path/to/chromedriver")
driver.get("https://web.whatsapp.com/")
time.sleep(10)
input("Qr Code: ")
driver.implicitly_wait(10)

numbers = driver.find_elements_by_class_name('_ccCW')
for n in numbers:
   print(n.text)

and my script is scraping only 17 items and whatsapp have 3 classes _ccCW FqYAR i0jNr and one of each class had 17 items so how scrape these three classes

CodePudding user response:

If the class names are _ccCW, FqYAR, and i0jNr then try

classes_to_get = ["_ccCW", "FqYAR", "i0jNr"]

for kls in classes_to_get:
    numbers = driver.find_elements_by_class_name(kls)
    for n in numbers:
       print(n.text)

CodePudding user response:

Try with this xpath:

//div[@role='gridcell']//span[@title]
numbers = driver.find_elements_by_xpath("//div[@role='gridcell']//span[@title]")
for n in numbers:
   print(n.text)
   #print(n.get_attribute("innerText")) # You can also use this line to print the text.

CodePudding user response:

You can construct a xpath with all 3 of them like below :

//*[contains(@class, '_ccCW') or contains(@class, 'FqYAR') or contains(@class, 'i0jNr')]

Code :

numbers = driver.find_elements_by_xpath("//*[contains(@class, '_ccCW') or contains(@class, 'FqYAR') or contains(@class, 'i0jNr')]")
for n in numbers:
   print(n.text)
  • Related