Skip to content
Advertisement

webscraping – get the first and the second value from the div tag with multiple values seperated by coma

I have a tag which looks like this

JavaScript

I would like to get only the name and surname so the “Pierre M” and the date “08/18/2018”

I was trying this code

JavaScript

But it results in taking every value from that tag so I get

JavaScript

Advertisement

Answer

You could go with find_all(text=True, recursive=False) to get only the first section of text in your specific case:

JavaScript

Alternativ would be to check for child <div> with updated, save its text if needed and decompose() it from the DOMuse of walrus operator needs python 3.8 or later else use standard if statement):

JavaScript
Example
JavaScript
Output
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement