Created
August 12, 2021 23:27
-
-
Save YusukeIwaki/72ab158ab305d15e175023498f77b5fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'playwright' | |
force_login = false | |
Playwright.connect_to_playwright_server('ws://127.0.0.1:8000/ws') do |playwright| | |
playwright.chromium.launch(headless: false, channel: 'chrome-canary') do |browser| | |
page = browser.new_page | |
page.goto('https://vaccines.sciseed.jp/fukuokacity/') | |
require 'pry' | |
binding.pry | |
page.context.storage_state(path: 'mystate.json') | |
end if force_login | |
playwright.chromium.launch(channel: 'chrome-canary') do |browser| | |
page = browser.new_page(storageState: 'mystate.json') | |
page.goto('https://vaccines.sciseed.jp/fukuokacity/reservation-date') | |
page.click('text=新規予約') | |
page.click('text=日付から探す') | |
page.click('.s-selector') # 摂取ワクチンを選択してください | |
page.click('text=ファイザー社ワクチン') | |
page.click('.page-search-reservation-frame-from-date_date') # 日付 | |
datepicker = page.query_selector('.page-search-reservation-frame-from-date_datepicker') | |
page.wait_for_selector('.cell.day') | |
selectable_days = datepicker.query_selector_all('.cell.day:not(.disabled)').map(&:text_content) | |
datepicker.wait_for_selector("text=#{selectable_days.first}").click | |
page.check('input[type="checkbox"]') # 予約可能な会場のみ表示 | |
selectable_days.each do |day| | |
page.click('.page-search-reservation-frame-from-date_date') # 日付 | |
datepicker = page.query_selector('.page-search-reservation-frame-from-date_datepicker') | |
page.wait_for_selector('.cell.day') | |
datepicker.wait_for_selector(".cell.day >> text=#{day}").click | |
# API通信の完了を待つ。 | |
# ただし、最初の1つは現在選択中なのでAjax request/responseされない。 | |
page.expect_event('response') unless day == selectable_days.first | |
items = page.query_selector_all('.department-list-item') | |
next if items.empty? | |
puts "#{day}日:" | |
items.each do |item| | |
name = item.query_selector('.department-list-item_name').text_content.strip | |
station = item.query_selector('.department-list-item_nearest-station').text_content.strip | |
area = item.query_selector('.department-list-item_area').text_content.strip | |
puts "--> #{name} (#{station}/#{area})" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment