Поиск в Google по драматургуPython

Программы на Python
Anonymous
Поиск в Google по драматургу

Сообщение Anonymous »

Я пытаюсь выполнить поиск в Google с помощью драматурга.
Но получаю эту ошибку:
playwright._impl._errors.TimeoutError: Page.fill: Timeout 60000ms exceeded.
Call log:
waiting for locator("input[name=\"q\"]")

Вот код:
from playwright.async_api import async_playwright
import asyncio

async def main():
async with async_playwright() as pw:
browser = await pw.chromium.launch(args=["--disable-gpu", "--single-process", "--headless=new"], headless=True)

page = await browser.new_page()

# Go to Google
await page.goto('https://www.google.com')

# Accept the cookies prompt (if it appears)
try:
accept_button = await page.wait_for_selector('button:has-text("I agree")', timeout=5000)
if accept_button:
await accept_button.click()
except:
pass

# Search for a query
query = "Playwright Python"
await page.fill('input[name="q"]', query, timeout=60000)
await page.press('input[name="q"]', 'Enter')

# Wait for the results to load
await page.wait_for_selector('h3')

# Extract the first result's link
first_result = await page.query_selector('h3')
first_link = await first_result.evaluate('(element) => element.closest("a").href')
print("First search result link:", first_link)

await browser.close()

if __name__ == '__main__':
asyncio.run(main())

Вернуться в «Python»