Вот как я создаю ссылку.
Код: Выделить всё
URL = "https://docs.google.com/spreadsheets/d/"
ID = "1ZUG5Xlesc-e1EfGg_T16vamQ_igMXvPb6VNQoWZegDE"
PARAM = [
'/export?exportFormat=pdf&format=pdf',
'&size=LETTER',
'&portrait=true',
'&fitw=true',
'&top_margin=0.75',
'&bottom_margin=0.75',
'&left_margin=0.7',
'&right_margin=0.7',
'&sheetnames=false&printtitle=false',
'&pagenum=UNDEFINED',
'&gridlines=true',
'&fzr=FALSE'
]
params = ''
for param in PARAM:
params += param
CALL = URL + ID + params
Ниже приведен код, который я использовал для OAuth2, но я не знаю, как я могу использовать аутентификацию для отправки запроса.
Код: Выделить всё
from requests_oauthlib import OAuth2Session
import os
os.environ["OAUTHLIB_RELAX_TOKEN_SCOPE"] = ' '
client_id = xxx
client_secret = xxx
redirect_uri = 'http://localhost'
scope = ['https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile']
oauth = OAuth2Session(client_id, redirect_uri=redirect_uri, scope=scope)
authorization_url, state = oauth.authorization_url(
"https://accounts.google.com/o/oauth2/auth",
access_type="offline",
prompt="select_account")
print(f'Please go to {authorization_url} and authorize access.')
authorization_response = input('Enter the full callback URL - ')
token = oauth.fetch_token(
"https://oauth2.googleapis.com/token",
code=authorization_response,
client_secret=client_secret)
r = oauth.get('https://www.googleapis.com/oauth2/v1/userinfo')
for i in r:
print(i)
Я хочу избегать таких вещей, как Selenium, потому что они часто приводят к проблемам с капчей.
Подробнее здесь: https://stackoverflow.com/questions/792 ... n-requests
Мобильная версия