Skip to content

[NODRIVER] Extract attributes. #2165

@Snegovik777

Description

@Snegovik777

Hi guys. I'm trying using NODRIVER to extract attributes from tags and text. But there's an error.

Error data extract: 'coroutine' object has no attribute 'attributes'
Error data extract: 'coroutine' object has no attribute 'attributes'
Error data extract: 'coroutine' object has no attribute 'attributes'
Error data extract: 'coroutine' object has no attribute 'attributes'
Error data extract: 'coroutine' object has no attribute 'attributes'

The documentation mentions Element.attributes. but...
maybe I need to rewrite the code differently?!!
I'd be grateful for any hint!!!

    products = await page.query_selector_all('.lu-grid__item')
    product_list = []
    for product in products[:5]:
        try:
            title_element = product.query_selector('a .lu-product-card-name')
            attributes = title_element.attributes
            title = attributes.get('title')
            print(title)
            price_element = product.query_selector('.product-card-main-content .price-and-buttons .main-price')
            price = price_element.text
            print(price)
            url_element = product.query_selector('a')
            attributes = url_element.attributes
            url = attributes.get('href')
            print(url)
            product_list.append({
                "title": title,
                "price": price,
                "url": url
            })
        except Exception as e:
            print(f"Error data extract: {e}")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions