Skip to content Skip to sidebar Skip to footer

Extract Href Values Containing Keyword Using Xpath In Python

I know variants of this question have been asked a number of times but I've not been able to crack it and get what I want. I have a website which has a few tables in it. The table

Solution 1:

Try something like:

href_elements = doc.xpath('//center//table//a[contains(@href,".txt")]["Text"]/@href')
for href in href_elements:
    print(href)

Output:

_alexandria_RIC_VI_099b_K-AP.txt
_alexandria_RIC_VI_100.txt
_alexandria_RIC_VI_136.txt
_alexandria_RIC_VI_156.txt

etc.

Post a Comment for "Extract Href Values Containing Keyword Using Xpath In Python"