I need to get the text inside the two elements into a string:
source_code = """<span class="UserName"><a href="#">Martin Elias</a></span>"""
>>> text
'Martin Elias'
How could I achieve this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I searched “python parse html” and this was the first result:
https://docs.python.org/2/library/htmlparser.html
This code is taken from the python docs
Here is the result:
Using this and by looking at the code in HTMLParser I came up with this:
You can use it like this:
Now you should be able to extract your data from those lists easily. I hope this helped!