<p>看起来每次都会生成CSS</p>
<p>我建议对此使用XPATH</p>
<p>使用<code>.text</code>获取文本</p>
<p>您可能希望更改为具有价格的父元素。。。因此,使用<code>(//div[@aria-label="Price trends are based on the Trulia Estimate"])[1]//../h3/div</code>作为xpath</p>
<pre><code>from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
import pandas as pd
import time
from bs4 import BeautifulSoup
import os
from datetime import datetime
from selenium.webdriver import ActionChains
driver = webdriver.Firefox(executable_path = 'geckodriver.exe')
def get_trulia_estimate(address):
driver.get('https://www.trulia.com/')
print(address)
element = (By.ID, 'homepageSearchBoxTextInput')
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(element)).click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(element)).send_keys(address)
search_button = (By.CSS_SELECTOR, "button[data-auto-test-id='searchButton']")
WebDriverWait(driver, 50).until(EC.element_to_be_clickable(search_button)).click()
time.sleep(3)
find_trulia_estimate_text = driver.find_element_by_xpath('(//div[@aria-label="Price trends are based on the Trulia Estimate"])[1]').text
print(find_trulia_estimate_text)
get_trulia_estimate('693 Bluebird Canyon Drive, Laguna Beach, CA 92651')
</code></pre>
<blockquote>
<p>693 Bluebird Canyon Drive, Laguna Beach, CA 92651
Trulia Estimate</p>
</blockquote>
<p>如果使用价格的xpath,则输出为:</p>
<blockquote>
<p>693 Bluebird Canyon Drive, Laguna Beach, CA 92651
$1,735,031</p>
</blockquote>