Is there a way to use bs4 to search for multiple attribute types with the same value?
I am scraping meta tags from news articles in order to get information like the title, author, and data published. There is some variation in how this data is structured between sites, and I would like to use the most compact code possible to cover the known possibilites.
For example the title could be in any of:
<meta content="Title of the article" property="og:title"/>
<meta content="Title of the article" property="title"/>
<meta name="Title of the article" property="og:title"/>
<meta name="Title of the article" property="title"/>
I can do something like this:
try:
soup.find('meta', {'property' : re.compile('title')})['content']
except:
soup.find('name', {'property' : re.compile('title')})['content']
But it would be nice if I could do something like this:
## No result returned
soup.find('meta', {re.compile('property|name') : re.compile('title')})
## TypeError: unhashable type: 'list'
soup.find('meta', {['property','name'] : re.compile('title')})
Is there something along these lines that would work?