Scrapy Playwright TimeoutError: Page.wait_for_selector: Timeout 30000ms Exceeded on WSL Ubuntu

I’m trying to use Scrapy with Playwright on WSL Ubuntu to scrape a website. However, I’m encountering a TimeoutError when the Page.wait_for_selector method is executed. The error message indicates that the timeout limit of 30000ms has been exceeded while waiting for the selector ‘li.pan5o1’ to be visible. How can I resolve this issue?

import scrapy
from scrapy_playwright.page import PageMethod
from CrowdA.items import CrowdAItem

def should_abort_request(request):
    if request.resource_type == "image":
        return True
    if request.method.lower() == 'post':
        return True
    return False

class CrowdASpider(scrapy.Spider):
    name = 'crowdAP'
    
    custom_settings = {
        'PLAYWRIGHT_ABORT_REQUEST' : should_abort_request
    }

    def start_requests(self):
        # URL to start scraping
        url = "https://www.grainger.com/category/hardware/braces-and-brackets?categoryIndex=1"
        
        # Set up request with meta data including Playwright configurations
        request = scrapy.Request(url, meta={
            'playwright': True,
            'playwright_include_page': True,
            'playwright_page_methods': [
                PageMethod("wait_for_selector", "li.pan5o1"), 
                PageMethod("evaluate", "window.scrollBy(0, document.body.scrollHeight)"),
            ],
            'errback': self.errback,
        })
        yield request

    async def parse(self, response):
        page = response.meta.get("playwright_page")
        if not page:
            self.logger.error("Playwright page is None")
        else:
            await page.close()

    async def errback(self, failure):
        page = failure.request.meta.get("playwright_page")
        if page:
            await page.close()

**Terminal Error :**
Traceback (most recent call last): 
File "/home/harry/Interview_Assignment/venv/lib/python3.12/site-packages/twisted/internet/defer.py", line 1999, in _inlineCallbacks result = context.run( 
File "/home/harry/Interview_Assignment/venv/lib/python3.12/site-packages/twisted/python/failure.py", line 519, in throwExceptionIntoGenerator return g.throw(self.value.with_traceback(self.tb)) 
File "/home/harry/Interview_Assignment/venv/lib/python3.12/site-packages/scrapy/core/downloader/middleware.py", line 54, in process_request return (yield download_func(request=request, spider=spider)) 
File "/home/harry/Interview_Assignment/venv/lib/python3.12/site-packages/twisted/internet/defer.py", line 1251, in adapt extracted: _SelfResultT | Failure = result.result() 
File "/home/harry/Interview_Assignment/venv/lib/python3.12/site-packages/scrapy_playwright/handler.py", line 340, in _download_request return await self._download_request_with_page(request, page, spider) 
File "/home/harry/Interview_Assignment/venv/lib/python3.12/site-packages/scrapy_playwright/handler.py", line 388, in _download_request_with_page await self._apply_page_methods(page, request, spider) 
File "/home/harry/Interview_Assignment/venv/lib/python3.12/site-packages/scrapy_playwright/handler.py", line 499, in _apply_page_methods pm.result = await _maybe_await(method(*pm.args, **pm.kwargs)) 
File "/home/harry/Interview_Assignment/venv/lib/python3.12/site-packages/scrapy_playwright/_utils.py", line 16, in _maybe_await return await obj 
File "/home/harry/Interview_Assignment/venv/lib/python3.12/site-packages/playwright/async_api/_generated.py", line 7812, in wait_for_selector await self._impl_obj.wait_for_selector( 
File "/home/harry/Interview_Assignment/venv/lib/python3.12/site-packages/playwright/_impl/_page.py", line 373, in wait_for_selector return await self._main_frame.wait_for_selector(**locals_to_params(locals())) 
File "/home/harry/Interview_Assignment/venv/lib/python3.12/site-packages/playwright/_impl/_frame.py", line 323, in wait_for_selector await self._channel.send("waitForSelector", locals_to_params(locals())) 
File "/home/harry/Interview_Assignment/venv/lib/python3.12/site-packages/playwright/_impl/_connection.py", line 59, in send return await self._connection.wrap_api_call( 
File "/home/harry/Interview_Assignment/venv/lib/python3.12/site-packages/playwright/_impl/_connection.py", line 513, in wrap_api_call raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None playwright._impl._errors.TimeoutError: Page.wait_for_selector: Timeout 30000ms exceeded. Call log: waiting for locator("li.pan5o1") to be visible

I attempted to run a Scrapy spider named CrowdASpider, which utilizes Playwright for web scraping. The spider is configured to wait for a specific selector (“li.pan5o1”) to be visible on the page before proceeding with parsing. However, when executing the spider, I encountered a TimeoutError indicating that the specified selector was not visible within the timeout period of 30,000 milliseconds.

I expected the spider to successfully wait for the selector to be visible and then proceed with parsing the page content. Instead, the TimeoutError occurred, suggesting that the selector was not found within the specified timeout period.

New contributor

Harshal Honde is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật