T
T
The_Immortal2020-09-08 03:04:29
Python
The_Immortal, 2020-09-08 03:04:29

Why does the regular expression with the tag not work?

I'm trying to rip out the text using reg. expression, under the tag that is inside a particular table:<nobr>

soup = BeautifulSoup(resArrow, 'lxml')
tbl = soup.find('tbl', id='maintbl')

for nobr in tbl.find_all('nobr', text=re.compile("MB")):
  # ничего не находится

An example of outputting the content of one of the required tags :<nobr>
<nobr>1895.35 MB<br/><a href="down.php?id=555"><b>2,55 tlm</b></a></nobr>

print (nobr.getText())issues
1895.35 MB2.55 tlm


In general, the key " MB " is, but for some reason it is not picked up in my regular expression. I already tried like this:
for nobr in tbl.find_all('nobr', text=re.compile(".*MB.*")):

Yes, and just indicated the exact line
for nobr in tbl.find_all('nobr', text="1895.35 MB2,55 tlm"):

for nobr in tbl.find_all('nobr', text="1895.35 MB"):
, but also found nothing.

What could be the problem?

Thank you!

PS I understand that instead of a regular expression, you can accept all tags in a row and then perform a comparison:<nobr>
for nobr in tbl.find_all('nobr'):
    if "MB" in nobr.getText(): # так работает
, but I really want to figure out what's wrong with the regular season.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor T2, 2020-09-08
@Viktor_T2

\s\d*,\d\d\s+MB(\s+|$)
https://regex101.com/r/TdncQ7/1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question