I'm trying to isolate a specific link for images from a web page but can't quite get there. The HTML looks something like:
<head>
<img alt="Generic title" src="https://genericURL/photo/picture.jpg/">
<img src="https://genericurl/.../">
<img src="https://genericurl/.../">
....
I am able to return many links but the link I specifically want is the top one shown, it is the only link containing /photo/picture.jpg.
I have tried using the answer from Find specific link text with bs4 and other variations but haven't figured it out yet. Is anyone able to take a look please?
My code:
links = soup.findAll('img', {'src': re.compile('^http://image\d+')})
for link in links:
print(link.text)
EDIT: Using the suggestions I realised that the link format was changing based on the filter I was using, e.g.: when I was printing the entire web page I saw the link as http://image.... However when I was using findAll('img', {'src' ... the link was outputting as https://img so I was trying to re.compile the wrong things.
re.compile("photo/picture.jpg")?