你如何使用Xpath的开头选择VALUES?

时间:2017-10-01 07:57:13

标签: python xpath

<!DOCTYPE HTML>
<html>
  <head>
    <title> SLIIT LIBRARY </title>
    <link rel = "stylesheet" type = "text/css" href = "Style.css"/>
    <script src = "//cdn.jsdelivr.net/webshim/1.14.5/polyfiller.js"></script>

    <script>

	  webshims.setOptions
	  ('forms-ext', 
		{
		  types: 'date'
		}
	  );
	
	  webshims.polyfill
	  (
        'forms forms-ext'
	  );
		
	  $.webshims.formcfg = 
	  {	
		en: 
		{
	      dFormat: '-',
	  	  dateSigns: '-',
		  patterns: 
		  {
		    d: "yy-mm-dd"
		  }
		}
	  };

    </script>

    <script type = "text/javascript" src = "http://code.jquery.com/jquery-2.1.4.min.js"></script>
 
    <script type = "text/JavaScript" src = "FormValidation.js"></script>

  </head>
  <body>

    <img src = "SLIIT.png" width = "300" height = "200" />
    <div class = "div-1">
      <ul class = "list-1">
	    <li>
          <a href = "Register to the system.html" target = "_blank"> Register </a>
        </li>
	    <li>
          <a href = "Login to the system.html" target = "_blank"> Staff </a> 
        </li>
      </ul>

      <h2> 
        <a href = "/SLIIT LIBRARY/" target = "_blank"> SLIIT LIBRARY</a>
      </h2>
    </div>

    <ul class = "list-2">
      <li> <a href = "/Home/" target = "_blank"> Home </a> </li>
      <li> <a href = "/Add Material/" target = "_blank"> Add Material </a> </li>
      <li> <a href = "/Search/" target = "_blank"> Search </a> </li> 
      <li> <a href = "/Borrowed Books/" target = "_blank"> Borrowed Books </a> </li>
      <li> <a href = "/Member Details/" target = "_blank"> Member Details </a> </li>
  </ul>

  <center>
    <h3>Adding New Material</h3>
    <form id = "add" name = "SLIIT Library" method = "POST" action = "" onsubmit = "return validateForm()">
      <table>
	    <tr>
		  <td>Item Number</td>
		  <td><input type = "text" name = "Item Number" id = "item" placeholder = "B001"></td>
	    </tr>
		
	    <tr>
		  <td>Item Type</td>
		  <td>
            <select name = "Item Type" id = "type">
		      <option>---Select One---</option>
			  <option>Book</option>
			  <option>Standard</option>
			  <option>Journal</option>
			  <option>CD</option>
			  <option>Article</option>
            </select>
		  </td>
	    </tr>
	
    	<tr>
		  <td>Category	</td>
		  <td>
            <select name = "Category" id = "category">
			  <option>---Select One---</option>
			  <option>Information Technology</option>
			  <option>Business Management</option>
			  <option>Enginerring</option>
			  <option>General</option>
            </select>
		  </td>
	    </tr>
	
	    <tr>
		  <td>Title	</td>
		  <td><input type = "text" name = "Title" id = "title" placeholder = "JavaScript and PHP"></td>
	    </tr>
		
	    <tr>
		  <td>Publisher	</td>
		  <td><input type = "text" name = "Publisher" id = "publisher" placeholder = "JavaScript and PHP"></td>
	    </tr>
	
	    <tr>
		  <td>Year of Publication	</td>
		  <td><input type = "date" name = "Year of Publication" id = "year"></td>
	    </tr>
	
	    <tr>
		  <td>Place of Publisher</td>
	      <td><input type = "text" name = "Place of Publisher" id = "place" placeholder = "England"></td>
	    </tr>
	
	    <tr>
		  <td>Abstract	</td>
		  <td><textarea name = "Abstract" id = "Abstract" rows = "3" cols = "18"></textarea>
	    </tr>
	
	    <tr>
		  <td>Medium	</td>
		  <td>
            <select name = "Medium" id = "medium">
			  <option>---Select One---</option>
			  <option>English</option>
			  <option>Sinhala</option>
			  <option>Tamil</option>
            </select>
		  </td>
	    </tr>
	
	    <tr>
		  <td>Edition	</td>
		  <td><select name = "Edition" id = "edition"/>
			<option>---Select One---</option>
		  </td>
	    </tr>
	
	    <tr>
		  <td>ISBN/ISSN No	</td>
		  <td><input type = "text" name = "ISBN/ISSN No" id = "number"></td>
	    </tr>
	
	    <tr>
		  <td>Shelf Number	</td>
		  <td><input type = "number" name = "Shelf Number" id = "shelf" min = "1"></td>
	    </tr>
	
	    <tr>
		  <td>Call Number	</td>
		  <td><input type = "number" name = "Call Number" id = "call" min = "1"></td>
	    </tr>
	
	    <tr>
		  <td>Bar Code No	</td>
		  <td><input type = "number" name = "Bar Code No" id = "barcode" min = "0"></td>
	    </tr>
	
	    <tr>
		  <td>No of Pages </td>
		  <td><input type = "number" name = "No of Pages" id = "pages" min = "1"></td>
	    </tr>

	    <tr>
		  <td></td>
		  <td>
            <input class = "button-1" type = "submit" name = "Insert" id = "submit" value = "Insert">
			<input class = "button-2" type = "reset" name = "reset" value = "Reset">
          </td>
	    </tr>   	
      </table>
    </form>
  </center>
  <div>
    <footer>
      <pre> Copyright &#169; Sri Lanka Institute of Information Technology, 2017 - All rights Reserved. </pre>
    </footer>
  </div>
</body>
</html>

我想要以“员工”开头的价值!

这不起作用 - 语法无效

<option value="Employee19343">Person1</option> <br />
<option value="Other19343">Person2</option> <br />

2 个答案:

答案 0 :(得分:1)

尝试使用以下选择器来获取确切的选项

HEAD~2

这将返回预期的选项

所以代码看起来应该是

//option[starts-with(@value, 'Employee')]

答案 1 :(得分:1)

由于单引号和双引号的使用不一致,您得到SyntaxError例外

尝试混合单/双引号,如下所示

value = tree.xpath("//option/@value[starts-with(.,'Employee')]")