擅长:python、mysql、java
<p>您需要选择更好的HTML,这里是解决方案。我使用了CSS选择器,因为它更准确;因为没有xPath在您的服务器上。在得到所有我们需要的东西后,将对象转换为文本,然后围绕可用的内容工作;然后在这里,我们分割行并删除换行符以获得更好的缩进</p>
<blockquote>
<p>Note: This has been tested and runs correctly.</p>
</blockquote>
<p>运行代码:</p>
<pre><code>import requests
from bs4 import BeautifulSoup
page = requests.get("https://www.winmar.ca/find-a-location/#267")
soup = BeautifulSoup(page.content, 'html.parser')
address = soup.select('#box-309 > div:nth-child(2) > p:nth-child(5)')
text = address[0].get_text()
print(text)
</code></pre>
<p>产出:</p>
<pre><code> 358 Keltic Drive Sydney River ,NS B1R 1V7
</code></pre>