Created
November 27, 2020 12:15
-
-
Save coding-youtuber/7e5fec9cccad61509652966d12275e95 to your computer and use it in GitHub Desktop.
【Python自動化】Googleフォームに自動回答する方法
This file contains 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
from selenium import webdriver | |
from time import sleep | |
import urllib.parse | |
import random | |
def main(): | |
""" | |
=====エラー解決情報(エラーが出たときの参考にしてください)===== | |
「selenium.common.exceptions.WebDriverException: Message: unknown error: Element is not clickable at point」 | |
https://qiita.com/DNA1980/items/528ff6269986b262acdc#%E5%95%8F%E9%A1%8C%E8%A7%A3%E6%B1%BA | |
「selenium.common.exceptions.WebDriverException: Message: unknown error: call function result missing 'value'」 | |
Python seleniumのsend_keysで出たエラーの対処方法 - Qiita | |
https://qiita.com/orangeboy/items/6fdddebc1dc919f6d9e1 | |
seleniumを使用しようとしたら、「"chromedriver"は開発元を検証できないため開けません。」と言われた - Qiita | |
https://qiita.com/apukasukabian/items/77832dd42e85ab7aa568 | |
=====間違っていたURL==== | |
https://docs.google.com/forms/d/e/1FAIpQLSc0QOFKz0DnOO9Wx9LPX3rs3mNghKRIftLC6SNgalsTJyAF7g/viewform?entry.1718818793=9999%20%20&entry.1486711776=%E5%B1%B1%E7%94%B0%E5%A4%AA%E9%83%8E%20%20&entry.171685049=1%E5%B9%B4A%E7%B5%84%20%20&entry.1138618080=%E9%87%8E%E7%90%83%E9%83%A8 | |
=====crontabの参考コード===== | |
* * * * * /bin/bash /Users/naoyashiga/youtube/naoya_tech/031_060/043_google_Form/reply_googleform.sh | |
""" | |
driver = webdriver.Chrome("/usr/local/bin/chromedriver") | |
# entry.[質問ID]=[回答] | |
student_number = 9999 | |
student_name = urllib.parse.quote("山田太郎") | |
class_name = urllib.parse.quote("1年A組") | |
club_name = urllib.parse.quote("野球部") | |
station_a = urllib.parse.quote("池袋駅") | |
station_b = urllib.parse.quote("上野駅") | |
# 36度1分〜7分になる | |
yesterday_taion = 36 + random.randint(1, 7) / 10 | |
today_taion = 36 + random.randint(1, 7) / 10 | |
parameter = "?usp=pp_url&entry.1718818793={}&entry.1486711776={}&entry.171685049={}&entry.1138618080={}&entry.309239632={}&entry.309239632={}&entry.426177823={}&entry.1537097308={}".format( | |
student_number, | |
student_name, | |
class_name, | |
club_name, | |
station_a, | |
station_b, | |
yesterday_taion, | |
today_taion | |
) | |
url = "https://docs.google.com/forms/d/e/1FAIpQLSc0QOFKz0DnOO9Wx9LPX3rs3mNghKRIftLC6SNgalsTJyAF7g/viewform{}".format(parameter) | |
try: | |
driver.get(url) | |
# ボタンが見える位置までスクロールしておく | |
sleep(2) | |
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") | |
sleep(2) | |
for e in driver.find_elements_by_css_selector(".freebirdFormviewerViewNavigationSubmitButton"): | |
e.click() | |
sleep(10) | |
finally: | |
driver.close() | |
driver.quit() | |
if __name__ == "__main__": | |
main() |
This file contains 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
now=$(date "+%Y%m%d_%H-%M-%S") | |
/Users/naoyashiga/.pyenv/versions/naoya-tech/bin/python3.8 /Users/naoyashiga/youtube/naoya_tech/031_060/043_google_Form/main.py >> /Users/naoyashiga/youtube/naoya_tech/031_060/043_google_Form/logs/${now}.log 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment