given text between two 'pre' tags as shown in the example code
I want to search for specified text... ABCD in the example
while ignoring any preceeding text on the line... "XYZ%7 " in the example
then put the six digits afterwards into a string... "141800" in the example
and also... how to put the entire line of text in a string... XYZ57 ABCD 141800" so I can manage it with the Python string methods.
thanks for any help.
I want to search for specified text... ABCD in the example
while ignoring any preceeding text on the line... "XYZ%7 " in the example
then put the six digits afterwards into a string... "141800" in the example
and also... how to put the entire line of text in a string... XYZ57 ABCD 141800" so I can manage it with the Python string methods.
thanks for any help.
html = '''\ <html> <body> <pre> Text in a pre element is displayed in a fixed-width XYZ57 ABCD 141800 font, and it preserves both spaces and line breaks </pre> </body> </html>''' import bs4 as bs soup = bs.BeautifulSoup(html,'lxml') y = soup.find('pre') print (y) print ("\ndebug break 1\n") # goal = find ABCD ###### and ignore the # first 5 characters and space at line begining # as they may not always be the same y=str(y) print (type(y)) if "ABCD" in y: print ('found it') # OK ABCD is in the string now how do I capture the # six digits after it? 141800 in this example