我正在尋找從這個網站刮取一些資訊。https://www.vogue.it/moda/gallery/met-gala-2021-red-carpet-look-ospiti-celeb
我要做的是刮取照片下的所有描述,例如 "Billie Eilish in Oscar de la Renta custom-made","Timothée Chalamet in Haider Ackermann e Converse "等等。我認為描述的名稱是".gallery-slide-caption__dek-container",但它并沒有搜刮到任何東西。 我的代碼是:
import pprint
detail_looks = []
for look in list_looks:
title = ""
if(len(look.find_elements_by_css_selector(".gallery-slide-caption__dek-container")) > 0):
title = look.find_elements_by_css_selector("gallery-slide-caption__dek-container") [0].text
detail_looks.append({'title': title})
len(detail_looks)
pprint.pprint(detail_looks[0:5])
但是輸出是空的。[{'title': ''}, {'title': ''}, {'title': ''}, {'title': ''}]
你能幫助我嗎?謝謝你
uj5u.com熱心網友回復:
為了得到所有的標題,你可以用class="gallery-slide-caption__dek "選擇所有的標簽:
import 請求
from bs4 import BeautifulSoup
url = "https://www.vogue.it/moda/gallery/met-gala-2021-red-carpet-look-ospiti-celeb"/span>
soup = BeautifulSoup(requests.get(url).content, "html.parser")
for i, caption in enumerate(soup.select(".gallery-slide-caption__dek"), 1) 。
print(i, caption.get_text(strip=True))
列印:
1 Billie Eilish in Oscar de la Renta custom-made
2 蒂莫西-查拉梅(Timothée Chalamet)身著Haider Ackermann e Converse的服裝
3 阿曼達-戈爾曼(Amanda Gorman)身著薇拉-王(Vera Wang)時裝
4 Keke Palmer
5 Bee Carrozzini 穿著華倫天奴高級定制時裝
...等等。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/320248.html
標籤:
