Это, вероятно, проще сделать с помощью requests
. Если вы просматриваете страницу в Chrome / Firefox, когда прокручиваете область списка, она отправляет GET-запросы на дополнительные данные. Конечная точка: /list-view-load.php?landscape_id=31&landscape_nid=33192®ion=All&category=All&subcategory=All&search=&custom1=&custom2=&custom3=&custom4=&custom5=&offset=20
, смещение увеличивается на 20 для каждого запроса.
Вы можете имитировать это с помощью:
import requests
from lxml import html
sess = requests.Session()
url = ('https://af.ktnlandscapes.com/sites/all/themes/landscape_tools/functions'
'/list-view-load.php?landscape_id=31&landscape_nid=33192®ion=All&'
'category=All&subcategory=All&search=&custom1=&custom2=&custom3=&'
'custom4=&custom5=&offset={offset}')
gets = []
for i in range(50):
data = sess.get(url.format(offset=20*i)).json().get('data')
if not data:
break
gets.append(data)
print(f'\rfinished request {i}', end='')
else:
print('There is more data!! Increase the range.')
listings = []
for g in gets:
h = html.fromstring(g)
listings.extend(h.xpath('tr/@listing'))
print('Number of listings:', len(listings))
# prints:
Number of listings: 339
listings
# returns
['91323', '91528', '91282', '91529', '91572', '91356', '91400', '91445',
'91373', '91375', '91488', '91283', '91294', '91324', '91423', '91325',
'91475', '91415', '91382', '91530', '91573', '91295', '91326', '91424',
...
'91568', '91592', '91613', '91569', '91593', '91594', '91570', '91352',
'91414', '91486', '91353', '91304', '91311', '91354', '91399', '91602',
'91571', '91610', '103911']