I am trying to make a selenium script in python that shows how many reviews a seller on bol.com has. Every time, I get the error selenium.common.exceptions.TimeoutException: Message:
. Here is my code:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Firefox()
driver.get("https://www.bol.com/nl/v/looliving-nl/1146429/")
reviews = WebDriverWait(driver,30).until(EC.visibility_of_element_located((By.XPATH,"//div[@class='media_body'/following::p"))).text
print(reviews)
How would I fix my script?
Have you tried requests
and lxml
? This may solve your problem...but like Greg mentioned, this depends on the website source.
import requests
from lxml import html
page = requests.get("https://www.bol.com/nl/v/looliving-nl/1146429/")
tree = html.fromstring(page.content)
reviews = tree.xpath("//div[@class='media_body'/following::p")
Incorrect expression: //div[@class='media_body'/following::p
.
You can use this xpath
: //div[@class='media__body']//p
reviews = WebDriverWait(driver,30).until(EC.visibility_of_element_located((By.XPATH,"//div[@class='media__body']//p"))).text
print(reviews)
Console output:
Totaal aantal beoordelingen: 6
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.