I have a string variable containing the HTML of an email.
The email contains Google drive attachments(links)
I extract the attachment ID of the same and the Google drive attachments are always in the following format:
'https://drive.google.com/file/d/123456789/view?/usp=drive_web'
123456789 being the file ID which I am trying to extract
When there is only one attachment, I extract the ID using the below code:
html_string.split('<a href "https://drive.google.com/file/d/')[-1].split('/')[0]
However, I do not know how to extrapolate this where there are multiple file IDs in the HTML string.
I am looking to find a list of all the strings between
this substring - '<a href "https://drive.google.com/file/d/'
and the next immideate '/'
example:
a small sample HTML file looking like so:
<a href ='https://drive.google.com/file/d/123456789/view?/usp=drive_web' >attachment_1</a>random HTML text with multiple '/'<a href ='https://drive.google.com/file/d/987654321/view?/usp=drive_web' >attachment_2</a>
Need to extract the following list :
['123456789','987654321']
Using a code that would work for any number of attachments
Once you fix your html_string.split call, you'll find it is returning a list whose elements (except for the first) each start with one of the numbers you want.
Find list of strings between 2 substring combinations in Python