speedyrazor
speedyrazor

Reputation: 3205

Python find tag in XML using wildcard

I have this line in my python script:

url = tree.find("//video/products/product/read_only_info/read_only_value[@key='storeURL-GB']")

but sometimes the storeURL-GB key changes the last two country code letters, so I am trying to use something like this, but it doesn't work:

url = tree.find("//video/products/product/read_only_info/read_only_value[@key='storeURL-\.*']")

Any suggestions please?

Upvotes: 4

Views: 1831

Answers (1)

paul trmbrth
paul trmbrth

Reputation: 20748

You should probably try .xpath() and starts-with():

urls = tree.xpath("//video/products/product/read_only_info/read_only_value[starts-with(@key, 'storeURL-')]")
if urls:
    url = urls[0]

Upvotes: 7

Related Questions