擅长:python、mysql、java
<p>使用<code>beautifulsoup</code>的版本:</p>
<pre><code>import requests
from bs4 import BeautifulSoup
url = 'https://www.trulia.com/json/search/location/?query={}&searchType=for_sale'
search_string = '693 Bluebird Canyon Drive, Laguna Beach, CA 92651'
headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0'}
d = requests.get(url.format(search_string), headers=headers).json()
property_url = 'https://www.trulia.com' + d['url']
soup = BeautifulSoup(requests.get(property_url, headers=headers).text, 'lxml')
print(soup.select_one('h3:has(+div span:contains("Trulia Estimate"))').text)
</code></pre>
<p>印刷品:</p>
<pre><code>$1,735,031
</code></pre>
<p>CSS选择器<code>h3:has(+div span:contains("Trulia Estimate"))</code>发现<code><h3></code>的标签<code><div></code>包含<code><span></code>和字符串“Trulia Estimate”作为直接同级</p>
<p>进一步阅读:</p>
<p><strong><a href="https://www.w3schools.com/cssref/css_selectors.asp" rel="nofollow noreferrer">CSS Selectors Reference</a></strong></p>