0

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

bawse
  • 130
  • 4
  • 21

2 Answers2

-1

you can change the default settings of opening the browser as any site uses its region of the browser to show language. you could manually go into settings and set the region in session or you can just use the execute_cdp_cmd method to set region by default

You can use: https://chromedevtools.github.io/devtools-protocol/tot/Emulation/#method-setGeolocationOverride

check out this for a detailed explanation: https://stackoverflow.com/a/60473486/8835695

tushi43
  • 60
  • 1
  • 6
-1

I ended up resolving this issue by just using the chromium.launch() method in Headless=False mode. That visually highlighted the problems with my original script.

After debugging in headful mode, switched back to headless and worked as normal.

bawse
  • 130
  • 4
  • 21