1

I've question about how to get value from input html when the tag position is dynamic. This is the example input:

<input type="text" autocomplete="" name="confirmedEmailAddress" id="emailaddress" maxlength="60" value="fname.lname@gmail.com" class="txt-box  txtbox-m "  aria-describedby="" aria-required="true" disabled="disabled">

<input type="text" autocomplete="" value="fname.lname@gmail.com" name="confirmedEmailAddress" id="emailaddress" maxlength="60" class="txt-box  txtbox-m "  aria-describedby="" aria-required="true" disabled="disabled">

This is what I'm able to do, but can not detect if tag value position before id position like in the second example.

/<input(?:.*?)id=\"emailaddress\"(?:.*)value=\"([^"]+).*>/i

2 Answers2

4

You can try this:

<input.*?(?:id=\"emailaddress\".*?value=\"([^"]+)|value=\"([^"]+).*?id=\"emailaddress\")[^>]*>

Demo

The matches are shown on the right pane (not visible on test string for some reason). Since there's a |, you'll have to check both group 1 and group 2.

As many pointed out though, this is not something that should be done with regular expressions if you can avoid it.

Jeto
  • 14,596
  • 2
  • 32
  • 46
0

You can use "Beautiful Soup" module.

from bs4 import BeautifulSoup
html = '''<input type="text" autocomplete="" name="confirmedEmailAddress" id="emailaddress" maxlength="60" value="fname.lname@gmail.com" class="txt-box  txtbox-m "  aria-describedby="" aria-required="true" disabled="disabled">
        <input type="text" autocomplete="" value="fname.lname@gmail.com" name="confirmedEmailAddress" id="emailaddress" maxlength="60" class="txt-box  txtbox-m "  aria-describedby="" aria-required="true" disabled="disabled">'''
soup = BeautifulSoup(html,"lxml")
print(soup.find(id="emailaddress")['value'])

In front end app,can you use jquery.js?

$("#emailaddress").val()

document.getElementById('emailaddress').value
William Feirie
  • 624
  • 3
  • 7