Reputation: 435
I try to get links whose title contains some word in the mean time not contains some words, I use the following code but it says is not a valid XPath expression.
Please find my code here:
Any help will be highly appreciated!
driver.get("http://www.csisc.cn/zbscbzw/isinbm/index_list_code.shtml")
while True:
links = [link.get_attribute('href') for link in driver.find_elements_by_xpath("//a[(contains(@title,'公司债券')and not(contains(@title,'短期'))]")]
for link in links:
driver.get(link)
#dosth
Upvotes: 1
Views: 3411
Reputation: 315
There is an extra bracket in you xpath, use
links = [link.get_attribute('href') for link in driver.find_elements_by_xpath("//a[contains(@title,'公司债券')and not(contains(@title,'短期'))]")]
instead You can use chrome developer tools first to validate your xpaths PS: I changed the xpath here a bit to be able to find some elements in my page
Upvotes: 4
Reputation: 4869
There should be space before and
. Also there is extra leading bracket in your XPath. Try:
"//a[contains(@title,'公司债券') and not(contains(@title,'短期'))]"
Upvotes: 1