0
我想要废除html数据与beautifulsoup,我想知道你是如何废除拥有一个类的类。 (双班)。在这里我的HTML代码来理解:与beautifulsoup多个类
<span class="phone-contacts">
<span class = "phone">
<span class = "label">
phone
</span>
<span class = "value">
<a class="tel" href="tel:+41XXXXXX">
021 XXX XX XX
</a>
</span>
</span>
<span class = "mobile">
<span class = "label">
Mobile
</span>
<span class = "value">
<a class="tel" href="tel:+41XXXXXX">
079 XXX XX XX
</a>
</span>
</span>
</span>
你可以看到,谁定义电话和移动的最后一堂课是“电话”,这是我的问题,我想利用手机和电话一个词典separetly像这样:
def bot_get_data(item_url):
source_code = requests.get(item_url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, "html.parser")
name_company = soup.find_all("h1")
phone_number = soup.find_all("a", {"class": "phone"}, {"class": "tel"})
#my problem is here : I have to find a way to go in a class who owns another
mobile_number = soup.find_all("a",{"class": "mobile"}, {"class": "tel"})
site_name = soup.find_all("a", {"class": "redirect"})
email_name = soup.find_all("a", href=re.compile('mailto'))
name_data = []
phone_data = []
mobile_data = []
site_data = []
mail_data = []
for item in name_company:
name_data.append(item.string)
print(item.string)
for num in phone_number:
phone_data.append(num.string)
print(num.string)
for mob in mobile_number:
mobile_data.append(mob.string)
print(mob.string)
for site in site_name:
site_data.append(site.string)
print(site.string)
for email in email_name:
mail_data.append(email.string)
print(email.string)
有没有人知道如何做到这一点与beautifulsoup?
感谢=)