P
P
ponideal2020-02-13 14:08:32
Python
ponideal, 2020-02-13 14:08:32

How to compose an xpath query in python?

r = s.get(url, headers=headers)
    tree = html.fromstring(r.text)
    our_path = f'//*[@data-id="{data_id}"]'
    a = tree.xpath(our_path)
    b = tree.xpath('//title/text()')


When I get b, then everything is OK, there is a text output. in a the answer is:
[<Element tr at 0x16544a82590>, <InputElement 16544a82040 name=None type='checkbox'>] None


The question is how to get xml data?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2020-02-13
@ponideal

So you got the elements - take and get data from there ...
At least the text a[0].text , at least the contents of the tags a[0].get('tag') , at least the element itself in text form entirely using etree.tostring (a[0], pretty_print=True)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question