iT邦幫忙

0

[Python]Selenium 爬蟲Google登入警告訊息

  • 分享至 

  • xImage

各位版上大大好,
小弟我最近在研究網路爬蟲的技術,
期望可以幫我完成一些很瑣碎的工作,如網路簽到...XD
此外,一方面也可以爬取一些動態網頁的資料;
在學習過程中發現在Google Login那端會被Google阻擋,
找了一些網路文章發現有著各種方法可以破解,
可是不知道是不是因為文章比較久,所以都無法成功,
希望版上各位大神可以給我點建議,或者給我相關文章去閱讀學習也可以=))

Resource

  1. Automation Google login with python and selenium shows ""This browser or app may be not secure""
  2. Python – Selenium 繞過”這個瀏覽器或應用程式可能有安全疑慮”
  3. Answer a question I've tried login with Gmail or any Google services but it shows the following "This browser or app may not be secure" message: I also tried to do options like enable less secure app

Code

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
username, password = "abc", "123"

profile_path = "D:/Mozilla/Firefox/Profiles/zqzp1712.default-release"
profile = webdriver.FirefoxProfile(profile_path)
profile.set_preference("dom.webdriver.enabled", False)
profile.set_preference('useAutomationExtension', False)
profile.update_preferences()
desired = DesiredCapabilities.FIREFOX

driver = webdriver.Firefox(executable_path = "geckodriver.exe",
                            firefox_profile = profile, 
                            desired_capabilities = desired)

login_url = 'https://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount?redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&prompt=consent&response_type=code&client_id=407408718192.apps.googleusercontent.com&scope=email&access_type=offline&flowName=GeneralOAuthFlow'

driver.get(login_url)
time.sleep(1)
acct = driver.find_element(By.XPATH,"//input[@id='identifierId']")
acct.send_keys(username + Keys.RETURN)
time.sleep(1)
pwd = driver.find_element(By.XPATH, "//input[@name='password']")
pwd.send_keys(password + Keys.RETURN) 
time.sleep(1)

obarisk iT邦研究生 2 級 ‧ 2023-03-26 14:56:03 檢舉
有什麼理由一定要用 selenium 登入?
不是找一個已經登入的瀏覽器就好了?
kennex_x iT邦新手 4 級 ‧ 2023-03-28 15:59:18 檢舉
因為我是在公司的電腦進行測試使用,
公司電腦只要一關機全部的cookie 紀錄都會被清除喔,
因為公司每天簽到可以拿到點數,
有時候就會忘記簽到所以才想說有沒有辦法利用程式來幫我解決呢XD?
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
Oo_花之舞__oO
iT邦新手 1 級 ‧ 2023-03-25 16:29:30

Resource連結建議用markdown語法唷
然後三個都一樣的部落格文章ㄟ

裡面說用第三方登入可以繞過

怎麼沒有試試看~

更新:
markdown用法是指連結啦:


[文章標題](網址)

這樣子

其他的可能要再研究 加油唷

kennex_x iT邦新手 4 級 ‧ 2023-03-25 16:54:36 檢舉

花之舞 大大您好~
然後三個都一樣的部落格文章ㄟ
感謝提醒,已經修正囉~ XD

裡面說用第三方登入可以繞過
我嘗試過用它裡面所提供的code去嘗試登入,一樣會出現相同的錯誤訊息...

目前在問ChatGPT,但是他提供的方法目前測試也是無解QAQ

我要發表回答

立即登入回答