Home > Blockchain >  How to extract Persian texts with Selenium in Python?
How to extract Persian texts with Selenium in Python?

Time:08-01

How to extract Persian texts with Selenium in Python?? The name variable should be text, but it seems to be empty

from selenium import webdriver
from selenium.webdriver.common.by import By
website="https://www.digikala.com/product/dkp-3628808/روغن- 
زیتون-بی-بو- 
کریستال-طلایی-3000- 
میلی-لیتر/"
driver = webdriver.Chrome(executable_path=r"C:\Users\Qazal\anaconda3\Lib\site- 
packages\selenium\chromedriver.exe")
driver.get(website)
name=driver.find_element(By.XPATH,'//div[@]//a[@href="https://www.digikala.com/seller/AEVNX/"]')
name=name.text
name=name.encode("utf-8")
print(name)

screenshot of that element

CodePudding user response:

The Xpath expression //*[@]/div/a/p is producing the following output:

*emphasized text*from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import time
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

chrome_options = Options()
chrome_options.add_argument("--no-sandbox")

webdriver_service = Service("./chromedriver") #Your chromedriver path
driver = webdriver.Chrome(service=webdriver_service, options=chrome_options)
url='https://www.digikala.com/product/dkp-3628808/روغن-  زیتون-بی-بو-  کریستال-طلایی-3000-  میلی-لیتر/'
driver.get(url)
driver.maximize_window()
time.sleep(5)
for name in driver.find_elements(By.XPATH,'//*[@]/div/a/p'):
    print(name.text)

Output:

سراج احسان
رزاقی
  • Related