i'm unable to understand why in the below code:
- i put all the parsed page in x (ok)
- i create in l1 a list of items i'm interesting in with x.xpath (ok)
- i cycle through the elements in l1 assigning every single element to l2
- i try to find in l3 an element i'm interesting in with l2.xpath but I DON'T UNDERSTAND why i don't obtain in l3 only a list of one element, the one i should found in l2 element, but a list with all elements i would find if i would write x.xpath, in other words sub-elements from the entire page and not only inside the l2 element
Someone know the reason and can explain me the solution? Thank you.
from lxml.etree import HTML
from requests import Session
z = Session()
z.params = {"filter[entry_type]": "business"}
x = z.get("https://www.local.ch/it/q", params={"where": 'Chiasso'}).text
x = HTML(x)
l1 = x.xpath("//*[starts-with(@class, 'js-entry-card-container')]")
for l2 in l1:
l3 = l2.xpath("//*[starts-with(@class, 'lui-margin-vertical-zero')]")