Created
August 17, 2018 08:00
-
-
Save MKtalk/553536082c46b94145965a7fd88743b3 to your computer and use it in GitHub Desktop.
구글 설문지 정보 가져오기
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
# -*- coding: utf-8 -*- | |
import json | |
import re | |
import requests | |
base_url = 'https://docs.google.com/forms/d/1Zf-XM4WWG_6xisG83W8SQY2MueXEZzStPl9xiNH25u4' | |
response = requests.get(base_url).text | |
form_url = re.findall(r'<form action="(.+?)" ', response) | |
print('form url: {}'.format(form_url[0])) | |
# https://gist.github.com/davidbau/8c168b2720eacbf4e68e9e0a9f437838 | |
match = re.search( | |
r'FB_PUBLIC_LOAD_DATA_\s*=\s*(.*?);\s*</script>', response, re.DOTALL) | |
compressed = match.group(1) | |
jstext = re.sub(r'(?<=[,[])\s*,', 'null,', compressed) | |
js = json.loads(jstext) | |
if isinstance(js[0] ,list): | |
js = js[0] | |
data = js[1][1] | |
for d in data: | |
if d[3]: | |
# options | |
question = d[1] | |
entry_id = d[4][0][0] | |
print('entry: {}\nQ: {}'.format(entry_id, question)) | |
count = 0 | |
while count < len(d[4][0][1]): | |
print('{}'.format(d[4][0][1][count][0])) | |
count += 1 | |
else: | |
question = d[1] | |
entry_id = d[4][0][0] | |
print('entry: {}\nQ: {}'.format(entry_id, question)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment