I've written a script in python using xpath
to parse tabular data from a webpage. Upon execution, it is able to parse the data from tables flawlessly. The only thing that I can't fix is parse the table header
that means th
tag. If I would do the same using css selector, i could have used .cssselect("th,td")
but in case of xpath
I got stuck. Any help as to how I could parse the data from th
tag also will be highly appreciated.
Here is the script which is able to fetch everything from different tables except for the data within th
tag:
import requests
from lxml.html import fromstring
response = requests.get("https://fantasy.premierleague.com/player-list/")
tree = fromstring(response.text)
for row in tree.xpath("//*[@class='ism-table']//tr"):
tab_d = row.xpath('.//td/text()')
print(tab_d)