我一直在使用硒来刮擦站点以获取一些信息。 该信息隐藏在“查看更多”标签的后面,当我单击它时,该标签就会使用javascript显示。我尝试了许多不同的方法来使信息可见。而且它似乎没有用。
我已经尝试使用动作链和常规的xpath方法将功能链接在一起,但是它似乎仍然没有单击所有其他信息,并且按钮文本被打印到控制台而不是被单击。
def grabDetails(self):
facts = self.browser.find_elements_by_xpath("//section[@id='hdp-content']/main/div/div[4]")
for fact in facts:
details = fact.text
print(details)
def moreFeatures(self):
view_more_elements = WebDriverWait(self.browser, 20).until(EC.visibility_of_element_located((By.XPATH, "//a[contains(text(),'See More Facts and Features')]")))
# features.click()
ActionChains(view_more_elements).double_click().preform()
# self.browser.execute_script('arguments[0].scrollIntoView(true);', features)
我正试图从此页面打印出信息! here is the zillow page that im trying to scrap
其下面的更多部分
答案 0 :(得分:0)
您正在将view_more_elements
设置为WebDriverWait
对象而不是WebElement
。这将防止对象被单击。您只需要运行WebDriverWait
作为自己的调用,然后运行.click()
元素即可。
view_more_xpath = '//div[@class="read-more zsg-centered"]/a'
view_more_elements = WebDriverWait(self.browser, 20).until(EC.visibility_of_element_located((By.XPATH, view_more_xpath))
self.browser.find_element_by_xpath(view_more_xpath).click()
编辑:您实际上不需要将WebDriverWait
设置为view_more_elements
。您可以这样做:
view_more_xpath = '//div[@class="read-more zsg-centered"]/a'
WebDriverWait(self.browser, 20).until(EC.visibility_of_element_located((By.XPATH, view_more_xpath))
self.browser.find_element_by_xpath(view_more_xpath).click()