Reputation: 1803
In beautifulSoup I can target all elements by tag, i.e:
BeautifulSoup().find_all('img')
or by src attribute as long as I also specify an attribute value, i.e:
BeautifulSoup().find_all(attrs={"src": "some.domain.com/file."})
How can I target all elements with an src attribute regardless of whatever that src attributes value is?
Upvotes: 0
Views: 423
Reputation: 33384
If you have bs4 4.7.1 or above you can use the following css selector.
for item in soup.select('[src]'):
print(item)
Upvotes: 1
Reputation: 8954
Does this work for you?
BeautifulSoup().find_all(attrs={"src": re.compile('*')})
Upvotes: 1