我对如何在标记位置是动态时从输入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">
这是我能够做到的,但无法检测id位置之前的标签值位置,如第二个例子中那样。
/<input(?:.*?)id=\"emailaddress\"(?:.*)value=\"([^"]+).*>/i
答案 0 :(得分:0)
你可以使用&#34;美丽的汤&#34;模块。
user account
在前端应用中,你可以使用jquery.js吗?
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'])