I want to get a screenshot of the iTunes Connect login page when I use selenium's headless mode.

Asked 1 years ago, Updated 1 years ago, 81 views

Verified

  • Comment out and run the headless mode portion
    メThe part where you click by entering your email address or password also works without any problems

  • Verify that you can access the chrome front page in headless mode and take screenshots
    問題I was able to get it without any problems

Comment out and run the headless mode part
メThe part where you click by entering your email address or password also works without any problems

Go to the top page of chrome in headless mode and verify that you can take screenshots
問題I was able to get it without any problems

Based on the above, I would appreciate it if you could tell me if the iTunes Connect site is convenient or if there is any other way to avoid it.

I don't know much about the front desk, so I'd appreciate it if you could give me some advice.

Thank you for your cooperation.

(Added July 28, 2020)

  • Chromedriver-binary and ChromeDriver versions were changed to 84.0.4147.30 for verification, but the results remained the same

environment

Error Message Running in Headless Mode

$python save_ss_headless.py

DevTools listening on ws://127.0.0.1:52996/devtools/browser/16df0db5-7204-4ce7-ac85-fb9c8dff6275
[0723/173124.264:INFO:CONSOLE(2)] "Metrics config: No config provided via delegate or fetched via init(), using default/cached config values.", source: https://itunesconnect.apple.com/static/compiled/js/itunesconnect.min.13f6834e19c35e8917d9.js(2)
[0723/173124.267:INFO:CONSOLE(2)] "Metrics config: No config provided via delegate or fetched via init(), using default/cached config values.", source: https://itunesconnect.apple.com/static/compiled/js/itunesconnect.min.13f6834e19c35e8917d9.js(2)
[0723/173124.275: INFO:CONSOLE(2)] "mt-perfkit: enable to apply time offsets: environment.timeOriginOffset() returned a non-number value", source: https://itunesconnect.apple.com/static/compiled/js/itunesconnect.min.13f6834e19c35e8917d9.js(2)
[0723/173124.278:INFO:CONSOLE(2)] "mt-perfkit: enable to apply time offsets: environment.timeOriginOffset() returned a non-number value", source: https://itunesconnect.apple.com/static/compiled/js/itunesconnect.min.13f6834e19c35e8917d9.js(2)
[0723/173124.281: INFO:CONSOLE(2)] "mt-perfkit: enable to apply time offsets: environment.timeOriginOffset() returned a non-number value", source: https://itunesconnect.apple.com/static/compiled/js/itunesconnect.min.13f6834e19c35e8917d9.js(2)
[0723/173124.284:INFO:CONSOLE(2)] "mt-perfkit: enable to apply time offsets: environment.timeOriginOffset() returned a non-number value", source: https://itunesconnect.apple.com/static/compiled/js/itunesconnect.min.13f6834e19c35e8917d9.js(2)
[0723/173124.288:INFO:CONSOLE(2)] "mt-perfkit: enable to apply time offsets: environment.timeOriginOffset() returned a non-number value", source: https://itunesconnect.apple.com/static/compiled/js/itunesconnect.min.13f6834e19c35e8917d9.js(2)
[0723/17315.680:INFO:CONSOLE(2)] "Metrics config: No config provided via delegate or fetched via init(), using default/cached config values.", source: https://itunesconnect.apple.com/static/compiled/js/itunesconnect.min.13f6834e19c35e8917d9.js(2)

execution code

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions importTimeoutException
import chromedriver_binary
importos

options=webdriver.ChromeOptions()
options.add_argument('--headless')
# options.add_argument('--no-sandbox')
# options.add_argument('--disable-gpu')
# options.add_argument('--incognito')
# options.add_argument("window-size=1920,1080")

mail_account = 'Set email address'
password = 'Set Password'

driver=webdriver.Chrome(executable_path='chromedriver', options=options)
base_url='https://itunesconnect.apple.com/login'
# base_url='http://www.google.com/'
driver.get(base_url)
time.sleep(10) 
# Save screenshot under log
ss_dir=os.path.join(os.path.dirname(os.path.abspath(__file__))), "./log/")
driver.save_screenshot(ss_dir+'app_store_login_page'+".png")
# print('1/5')
# iframe=driver.find_element_by_css_selector('#aid-auth-widget-iFrame')
# driver.switch_to.frame(iframe)
# print("2/5")
# time.sleep(5)
# driver.find_elements_by_css_selector("#account_name_text_field")[0].send_keys(mail_account)
# driver.find_elements_by_css_selector("#sign-in")[0].click()
# print("3/5")
# time.sleep(5)
# driver.find_elements_by_css_selector("#password_text_field")[0].send_keys(password)
# driver.find_elements_by_css_selector('#sign-in')[0].click()
# time.sleep(5)
# print ("4/5")
driver.close()
driver.quit()

python web-scraping selenium

2022-09-30 14:40

1 Answers

After referring to the comment from Kunif, I was able to solve the problem, so I will write it down in my answer.

I checked the user-agent by referring to the following site and found that it was also run in headless mode!

Launch Options - Google Chrome Summary Wiki

--user-agent=""

Pretend to be a user agent to another browser.

I looked into the article further and used it as a reference

Browse in selenium under UA disguise with python - Qiita

I'm curious about the version I'm typing here, so I'm going to go to the link in the article
The newest chrome version was 83, but I changed the chromeDriver version to 84.0.4147.30, so I changed it to match the chrome version

Chrome User Agents-WhatIsMyBrowser.com

Based on the list of UserAgent on the above site, I added the following, and it was able to run in headless mode without any problems!

options.add_argument('--user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36')

You posted a list of arguments, so I was able to add a circle to this argument.

Thank you for your comment!


2022-09-30 14:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.