我无法使用类名或XPATH从特定容器中提取商品的价格。我试着拉不同的html块,但就是不起作用。价格格式应该是这样的₱38-₱120。这是网站https://shopee.ph/search?keyword=a4%20notebook
#all containers
container = driver.find_elements_by_xpath('//*[@class="_1gkBDw _2O43P5"]') #list
time.sleep(10)
#product
item_list = []
price_list = []
for item in container: #individual container
product = item.find_element_by_class_name('O6wiAW') #'//*[@class="O6wiAW"]' #specific container
item_list +=[product.text]
price = item.find_element_by_class_name('_1w9jLI _37ge-4 _2ZYSiu') #MY PROBLEM
price_list += [price.text]
print(price_list)
print(len(price_list))
print(item_list)
print(len(item_list))
exit(1)
要打印第一项的价格,即₱38-₱120,您需要为
visibility_of_element_located()
引入WebDriverWait,并且您可以使用以下任一Locator Strategies:使用
XPATH
:控制台输出:
注意:您必须添加以下导入:
相关问题 更多 >
编程相关推荐