【发布时间】:2020-11-22 00:04:38
【问题描述】:
在beautifulsoup 中提取文本时遇到问题:
data=requests.get("https://www.habitaclia.com/pisos-barcelona.htm?gclid=Cj0KCQiAkuP9BRCkARIsAKGLE8UM9G9s2MhPVtfXl2wo81qT62dqCwkVeV1zVSlPz_G1Nt0QcSoyKTYaAv55EALw_wcB")
soup=BeautifulSoup(data.text, "html5lib")
anuncis = soup.find_all("div", {"class":"list-item-info"})
data=[]
for anunci in anuncis:
preu = [anunci.find("span", attrs={"itemprop":"price"}).text]
data.append(preu)
print(data)
我尝试了不同的解析器 html、html5、xlml,但似乎都不起作用。
知道为什么我不能提取文本吗?
提前致谢。
干杯
【问题讨论】:
标签: python beautifulsoup