Does CSS extraction support the extraction of arrays? Currently, only one item can be extracted. #892
Unanswered
cccmolo
asked this question in
Forums - Q&A
Replies: 1 comment
-
|
@cccmolo Yes. we support extracting a list of items from a page. Here's an example, where we are getting a list of items from a restaurant menu. Check it out. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
`import asyncio
import json
from crawl4ai import AsyncWebCrawler, CrawlerRunConfig, CacheMode
from crawl4ai.extraction_strategy import JsonCssExtractionStrategy
async def main():
schema = {
"name": "Example Items",
"baseSelector": "div.item",
"fields": [
{"name": "title", "selector": "h2", "type": "text"},
{"name": "link", "selector": "a", "type": "attribute", "attribute": "href"}
]
}
raw_html = """
Item 1
Link 1Item 2
Link 2if name == "main":
asyncio.run(main())`
result:[{'title': 'Item 1', 'link': 'https://example.com/item1'}]
I hope so: [{'title': 'Item 1', 'link': 'https://example.com/item1'},{'title': 'Item 2', 'link': 'https://example.com/item2'}]]
Beta Was this translation helpful? Give feedback.
All reactions