seleniumとpyppeteerでブラウザ操作

Selenium

from selenium import webdriver

driver = webdriver.Firefox()

url = 'https://www.yahoo.co.jp/'

driver.get("https://tool-taro.com/wget/")

elem = driver.find_element_by_name("value")
elem.clear()
elem.send_keys(url)

elem = driver.find_element_by_class_name("lockable")
elem.click()

elem = driver.find_element_by_name("title")
title = elem.get_attribute("value")

print(title)

elem = driver.find_element_by_name("result")
value = elem.get_attribute("value")

print(value)

Pyppeteer

import asyncio
from pyppeteer import launch


async def main():

    browser = await launch()
    page = await browser.newPage()

    await page.goto('https://tool-taro.com/wget/')

    # URL入力
    await page.type('div.box_whois_l.box_wget03 > input[type="text"]',
                    'https://www.yahoo.co.jp/')

    # 取得ボタンクリック
    await page.click('div.box_whois_r > div > input')

    # 3秒待機
    await page.waitFor(3000)

    # タイトル
    element = await page.querySelector('#new > div.box_wget01 > textarea')
    title = await page.evaluate('(element) => element.value', element)

    # 本文
    element = await page.querySelector('#new > div.box_wget02 > textarea')
    description = await page.evaluate('(element) => element.value', element)

    print(title)
    print(description)

    # 画面キャプション
    await page.screenshot({'path': 'example.png'})
    await browser.close()


asyncio.get_event_loop().run_until_complete(main())