我想从this page那里得到一份价格表
我试图获取的元素的类名称为s-item\u price。 这是我的代码:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
url = 'https://www.ebay.de/sch/i.html?_from=R40&_nkw=iphone+8+&_sacat=0&LH_TitleDesc=0&LH_ItemCondition=3000&rt=nc&LH_Sold=1&LH_Complete=1'
chrome_options = Options()
chrome_options.add_argument('--headless')
browser = webdriver.Chrome(options=chrome_options)
browser.get(url)
print(browser.find_elements_by_class_name('s-item__price'))
browser.quit()
输出只是一个空列表
你会得到一张空名单,我想是因为你需要等待
使用
WebDriverWait
并使用.presence_of_all_elements_located
收集列表中的元素然后使用循环提取它们,您必须调用
.text
方法来获取文本以下内容:
您可以使用WebDriverWait等待javascript生成元素:
您也可以使用
presence_of_elements_located
,但如果涉及到单击交互,则无法使用隐藏元素。 所以更喜欢使用:visibility_of_element_located
示例代码:
相关问题 更多 >
编程相关推荐