【发布时间】:2020-07-09 09:47:22
【问题描述】:
我使用 BeautifulSoup 包在 Python 中解析了一些 HTML。这是 HTML:
<div class='n'>Name</div>
<div class='x'>Address</div>
<div class='x'>Phone</div>
<div class='x c'>Other</div>
我正在使用此代码块捕获结果:
names = soup3.find_all('div', {'class': "n"})
contact = soup3.find_all('div', {'class': "x"})
other = soup3.find_all('div', {'class': "x c"})
现在,“x”和“x c”两个类都被捕获在“contact”变量中。我怎样才能防止这种情况发生?
【问题讨论】:
-
classx在Address和Phone和Other上出现了3 次,为什么你只是不按位置取货?
标签: python html web-scraping beautifulsoup