Skip to content

Commit 14faf30

Browse files
authored
Add files via upload
1 parent 48999ed commit 14faf30

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const playwright = require('playwright');
2+
3+
(async () => {
4+
const browser = await playwright.chromium.launch();
5+
const page = await browser.newPage();
6+
await page.goto('https://books.toscrape.com/');
7+
const books = await page.$$eval('.product_pod', all_items => {
8+
const data = [];
9+
all_items.forEach(book => {
10+
const name = book.querySelector('h3').innerText;
11+
const price = book.querySelector('.price_color').innerText;
12+
const stock = book.querySelector('.availability').innerText;
13+
data.push({ name, price, stock});
14+
});
15+
return data;
16+
});
17+
console.log(books);
18+
console.log(books.length);
19+
await browser.close();
20+
})();

python/playwright-web-scraping/node/package-lock.json

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"playwright": "^1.27.0"
4+
}
5+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from playwright.async_api import async_playwright
2+
import asyncio
3+
4+
5+
async def main():
6+
async with async_playwright() as pw:
7+
browser = await pw.chromium.launch()
8+
page = await browser.new_page()
9+
await page.goto('https://books.toscrape.com')
10+
11+
all_items = await page.query_selector_all('.product_pod')
12+
books = []
13+
for item in all_items:
14+
book = {}
15+
name_el = await item.query_selector('h3')
16+
book['name'] = await name_el.inner_text()
17+
price_el = await item.query_selector('.price_color')
18+
book['price'] = await price_el.inner_text()
19+
stock_el = await item.query_selector('.availability')
20+
book['stock'] = await stock_el.inner_text()
21+
books.append(book)
22+
print(books)
23+
await browser.close()
24+
25+
if __name__ == '__main__':
26+
asyncio.run(main())
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
playwright

0 commit comments

Comments
 (0)