Probably every web browser in DevTools
has function to get XPATH
on right click.
But you could try also find unique ID
or CLASS
(or other unique value - ie. style=...
) for element. Or unique value for its parent or grandparent.
If there are many similar elements then you can get all of them and later use index
- all_times[1]
- to work only with one element.
It seems your element has unique headers="Times"
which you could use in xpath
.
You can also relative xpath
(starting with dot .
) and search partially - first find tr
, next find .//td[@headers="Times"]
in this tr
and next find .//td[@headers="Avaliable"]/div/a
in the same tr
EDIT:
If I couldn't find unique elements then I would get all tr
because it is parent for Times
and Avaliable
and I can use relative xpath to search one Times
and one Avaliable
in single tr
- and then use for
-loop
all_tr = html.xpath("//tr")
for tr in all_tr:
# relative xpath in `tr` (using `.` at start)
header = tr.xpath('.//td[@headers="Times"')
if "7:30" in header[0].text:
# relative xpath in `tr` (using `.` at start)
avaliable = tr.xpath('.//td[@headers="Avaliable"]')
avaliable[0].click()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…