Jul-08-2021, 12:53 PM
(Jul-08-2021, 11:58 AM)snippsat Wrote: Usetext
andattrs
.
Don't usefindAll('a')
(will be a list) in loop justfind('a')
Also usefind_all('a')
,the old CamleCase(do not use in Python) is kept for backward compatibility.
>>> from bs4 import BeautifulSoup >>> >>> html = '<a href="/vdi-software/">VDI Software</a>' >>> soup = BeautifulSoup(html, 'lxml') >>> tag = soup.find('a') >>> tag <a href="/vdi-software/">VDI Software</a> >>> >>> tag.text 'VDI Software' >>> tag.attrs.get('href', 'Not found') '/vdi-software/' >>> tag.attrs.get('car', 'Not found') 'Not found'
Hi snippsat,
Thanks so much for helping out and teaching me. Also appreciate you pointing out better practices re- find_all. Awesome to learn new stuff!