Relative Content

Tag Archive for web-scrapingplaywright

playwrigh locator doesn’t update the refernce for every looping time

the locator doesn’t be updated for every loop # loop scrolling last element into view until no more new elements are created stream_boxes = None while True: stream_boxes = page.locator(“//div[contains(@class,’tw-tower’)]/div[@data-target]”) stream_boxes.element_handles()[-1].scroll_into_view_if_needed() items_on_page = len(stream_boxes.element_handles()) page.wait_for_timeout(2_000) # give some time for new items to load items_on_page_after_scroll = len(stream_boxes.element_handles()) if items_on_page_after_scroll > items_on_page: continue # more items […]