i want to extract a number from a html string (i usually do not know the number).
The crucial part looks like this:
<test test="3" test="search_summary_figure WHR WVM">TOTAL : 286</test>
<tagend>
And i want to extract the "286". I want to do something like "start after "L :" and stop before "<". How can i do this ? Thank you very much in advance.
If the string "TOTAL : number" is unique then use a regular expression to first search this substring and then extract the number from it.
You can test your own regular expressions here https://regex101.com/
You can try the following like this below:
Output :
You can use string partitioning to extract a "number" string from the whole HTML string like this (assuming HTML code is in html_string variable):
num_string=html_string.partition("TOTAL:")[2].partition("<")[0]
there you get num_string with the number as a string, then simply convert it to an integer or whatever you want. Keep in mind that this will process the first occurence of anything that looks like "TOTAL: anything_goes_here <", so you want to make sure that this pattern is unique.
If your HTML String is this:
Try this:
in your view.py document you can try this: