Jump to content
Fórum Script Brasil
  • 0

Ler conteúdo com Simbolo euro


Mario Lopes
 Share

Question

Procuro um preço numa página web:

Eis o html da página:

arial,serif;font-size:18px;">9,95€</span></td>

O meu código

regex='arial,serif;font-size:18px;">(.+?) '
                pattern=re.compile(regex)
                price=pattern.findall(str(htmltext))

o valor de price é [] por causa do simbolo euro.

Como apanhar o valor 9,95?

Cumprimentos

Mário Lopes

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0
Em 02/04/2016 at 14:41, Mario Lopes disse:

arial,serif;font-size:18px;">9,95€</span></td>

Eu prefiro processar html com builtins

>>> s = 'arial,serif;font-size:18px;">9,95€</span></td>'
>>> s1 = s[:s.rfind('€')]
>>> s1
'arial,serif;font-size:18px;">9,95'
>>> s2 = s1[s1.rfind('>') + 1:]
>>> s2
'9,95'
>>> s3 = s2.replace(',', '.')
>>> s4 = float(s3)
>>> s4
9.95

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Forum Statistics

    • Total Topics
      149.6k
    • Total Posts
      646.2k
×
×
  • Create New...