Hey so im using selenium and im trying to scrape this line:
<em id="home-payOrderCommission" data-spm-anchor-id="portals._cps_home.overview.i0.6da22fe0oBPXYk">US $7.68</em>
Im trying to scrape the $7.68 part but I cant figure out how to do it, I tried by element ID but it doesn't seem to work
This is what I tried:
search = driver.find_element_by_id("portals._cps_home.overview.i0.2e1b2fe03tjTTD").text
print(search)
you are using the wrong id
use this instead :
id = 'home-payOrderCommission'
in code :
search = driver.find_element_by_id("home-payOrderCommission").text
print(search)
or a way better approach here is to use Explicit waits :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 10)
print(wait.until(EC.visibility_of_element_located((By.ID, "home-payOrderCommission"))).text)
PS :-
.text is a method available in Selenium-Python bindings, basically to get the text between the ID tag in your case, and in general to extract the text of an web element.
You are using a wrong locator.
As can be seen from the element you presented, it has id
attribute with value of home-payOrderCommission
and data-spm-anchor-id
attribute with value of portals._cps_home.overview.i0.6da22fe0oBPXYk
.
So, to use find_element_by_id
method the value is home-payOrderCommission
.
Try this:
search = driver.find_element_by_id("home-payOrderCommission").text
print(search)
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.