Python Forum
find chars after chars in 'pre' tag
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
find chars after chars in 'pre' tag
#1
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.


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
Reply


Messages In This Thread
find chars after chars in 'pre' tag - by Fran_3 - Aug-17-2017, 11:18 PM
RE: find chars after chars in 'pre' tag - by Fran_3 - Aug-19-2017, 04:27 PM
RE: find chars after chars in 'pre' tag - by Fran_3 - Aug-19-2017, 08:30 PM
RE: find chars after chars in 'pre' tag - by Fran_3 - Aug-20-2017, 02:56 PM
RE: find chars after chars in 'pre' tag - by Fran_3 - Aug-22-2017, 11:44 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020