seek in text

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • bvdet
    replied
    The following will get the value using re.[code=Python]
    import re
    s = '>EUR/SEK 1:1</a></td><td><div id=aq_eursek_o> 9.3055</div></td><td><div id=aq_eursek_h> 9.3216</div></td><td><div id=aq_eursek_l> 9.2905</div></td>'
    patt = re.compile(r'id =aq_eursek_h>([0-9.]+)')
    m = patt.search(s)
    if m: print m.group(1)[/code]

    >>> 9.3216
    >>>

    Leave a comment:


  • Subsciber123
    replied
    Originally posted by monkw
    hi
    i have to find in html code some key worlds and write them to the file.
    html text looks like this:
    Code:
     ... >EUR/SEK 1:1</a></td><td><div id=aq_eursek_o>9.3055</div></td><td><div id=aq_eursek_h>9.3216</div></td><td><div id=aq_eursek_l>9.2905</div></td> ...
    and i need value that is after " id=aq_eursek_h> "

    2nd question:
    i made it using sed script, how can i run sed script in python script?
    You can do:
    [CODE=python]S_STRING_1="id= aq_eursek_h>"
    S_STRING_2="</div>"
    string=YOUR_HTM L_CODE_HERE
    data=string[string.index(S_ STRING_1)+len(S _STRING_1):]
    data=data[:data.index(S_S TRING_2)]
    [/CODE]
    I'm not quite sure if this is what you want. It assumes that the HTML file will be exactly as you described, and simply searches for that string. You could also use the re module to do this in fewer lines (and faster), as an afterthought.

    Leave a comment:


  • monkw
    started a topic seek in text

    seek in text

    hi
    i have to find in html code some key worlds and write them to the file.
    html text looks like this:
    Code:
     ... >EUR/SEK 1:1</a></td><td><div id=aq_eursek_o>9.3055</div></td><td><div id=aq_eursek_h>9.3216</div></td><td><div id=aq_eursek_l>9.2905</div></td> ...
    and i need value that is after " id=aq_eursek_h> "

    2nd question:
    i made it using sed script, how can i run sed script in python script?
Working...