Reputation: 1
<option value="Employee19343">Person1</option> <br />
<option value="Other19343">Person2</option> <br />
. .
I want the value that starts with "Employee"!
This doesn't work - invalid syntax
value = tree.xpath('//option/@value[starts-with(.,'Employee')]')
Upvotes: 0
Views: 324
Reputation: 52695
You got SyntaxError
exception because of inconsistent usage of single and double quotes
Just try to mix single/double quotes as below
value = tree.xpath("//option/@value[starts-with(.,'Employee')]")
Upvotes: 1
Reputation: 1652
Try using below selector to get the exact option
//option[starts-with(@value, 'Employee')]
This will return expected options
So the code should look like
value = tree.xpath('//option[starts-with(@value, "Employee")]/@value')
Upvotes: 1