Nov-22-2018, 11:31 AM
(This post was last modified: Nov-22-2018, 11:31 AM by Broadsworde.)
I have HTML code like the following from a URL:
<img class="this" alt="this" src="this_source1.gif">
<img class="this" alt="this" src="this_source2.gif">
<img class="this" alt="this" src="this_source3.gif">
<img class="this and that" alt="not this" src="this__and_that_source1.gif">
<img class="this and that" alt="not this" src="this__and_that_source2.gif">
<img class="this and that" alt="not this" src="this__and_that_source3.gif">
I'm trying to get the alt value of just the img tags with only class="this"
How do I specify only to return class_="this"?
<img class="this" alt="this" src="this_source1.gif">
<img class="this" alt="this" src="this_source2.gif">
<img class="this" alt="this" src="this_source3.gif">
<img class="this and that" alt="not this" src="this__and_that_source1.gif">
<img class="this and that" alt="not this" src="this__and_that_source2.gif">
<img class="this and that" alt="not this" src="this__and_that_source3.gif">
I'm trying to get the alt value of just the img tags with only class="this"
import requests from bs4 import BeautifulSoup url = "https://someurl.com" resp = requests.get(url) txt = resp.text soup = BeautifulSoup(txt, 'lxml') imgThis = soup.find_all('img', class_='this') for i in (imgThis): imgThis[i]['alt']The find_all method returns alts for both class_="this" and class_="this and that"
How do I specify only to return class_="this"?