Webscrape非唯一标签



我正在努力刮(https://slashdot.org/software/p/MyCase/)对于

"39.00/月/用户";以及";基本计划:每位用户每月39美元(按年计费(或每位用户每月49美元(按月计费(专业计划:每位用户每月59美元(按年计费(或每位用户每月69美元(按月计费(高级计划:每个用户每月79美元(每年计费(或每个用户每月89美元(每月计费("然而,我不知道如何获取它们,因为它们(和其他(的标签是相同的:";div";class=";字段值";。

我怎么能和美容师单独拿这些呢。

您可以通过标签的文本获取所需的标签(例如,有很多方法(:

import requests
from bs4 import BeautifulSoup

url = "https://slashdot.org/software/p/MyCase/"
soup = BeautifulSoup(requests.get(url).content, "html.parser")
pricing_1 = soup.select_one(
'.field-label:-soup-contains("Pricing Starts At") + .field-value'
)
pricing_2 = soup.select_one(
'.field-label:-soup-contains("Pricing Information") + .field-value'
)
print(pricing_1.text)
print(pricing_2.text)

打印:

$39.00/month/user
Basic Plan: $39 per user/month (billed annually) or $49 per user/month (billed monthly)
Pro Plan: $59 per user/month (billed annually) or $69 per user/month (billed monthly)
Advanced Plan: $79 per user/month (billed annually) or $89 per user/month (billed monthly

最新更新