我对编程相当陌生,似乎无法解决以下数据提取问题。在
我的数据是这样的(黄色=我要提取的):
提取标题、价格和时间很好:
# Title
advertTitle = firstAdvert.find_all(
"section", {"class": "aditem-main"})[0].find("h2").text.encode("utf-8").strip().replace("\n", "")
# Price
advertPrice = firstAdvert.find_all(
"section", {"class": "aditem-details"})[0].find("strong").text.encode("utf-8").strip().replace("\n", "")
# Time
advertTimeAdded = advertTitle = firstAdvert.find_all(
"section", {"class": "aditem-addon"})[0].text.encode("utf-8").strip().replace("\n", "")
但我的主要问题是:我如何从中提取“79924470”:
^{pr2}$我试过这样的例子:
item.find_all("article", "data-adid"}
谢谢你给我指出了正确的方向!在
你可以这样做:
这应该将
data-adid
的每个值添加到列表data
。在由于使用的是BeautifulSoup,因此可以执行以下操作来提取属性的值:
可以使用一系列选择来获取以下各种元素:
显示:
^{pr2}$相关问题 更多 >
编程相关推荐