I'm trying to use the Playwright Async API as below to extract some data, and eventually to write some tests.
from playwright.async_api import async_playwright
async def aliexpress(browser_url, product_url):
async with async_playwright() as pw:
browser = await pw.chromium.connect_over_cdp(browser_url)
try:
page = await browser.new_page()
await page.goto(product_url, timeout=None);
nav_description = await page.locator('#product-description').inner_text();
print(nav_description);
return nav_description;
finally:
await browser.close();
The product_url
is simply set to the AliExpress product page, e.g. https://www.aliexpress.com/item/{productId}.html
The above code works, but I'm getting the results in a different language than I want. There's a switcher present on each page which allows the user to change the default language and currency. I want to be able to check the language on page load, if incorrect, set it to the correct one (e.g. Spanish) and save. From my limited understanding, this is something that's probably auto-detected from AliExpress. I'm not aware of setting the defaults via any other methods.
I've tried to use other locators to click and set the language but that hasn't worked. Could someone suggest a way to set the language?
Thanks