'scraping NYT mini crossword stats gives 403 forbidden URL error
I'm trying to scrape my NYT mini crossword stats to then update a google sheet. But I'm having trouble with the login portion of the code. Here's my code so far:
from http import cookies
import pandas as pd
import requests
from bs4 import BeautifulSoup
import re
s = requests.session()
nyt_login_url = 'https://myaccount.nytimes.com/'
login_route = 'svc/lire_ui/login'
auth_token = 'my auth token from requests'
HEADERS = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36',
'origin': nyt_login_url,
'referer': nyt_login_url + login_route
}
login_payload = {
'login': 'myusername',
'password': 'mypassword',
'authtoken': auth_token
}
login_req = s.post(nyt_login_url + login_route, headers = HEADERS, data = login_payload)
print(login_req.raise_for_status())
When I run this I receive the following error:
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://myaccount.nytimes.com/svc/lire_ui/login
If I successfully log in, the status code should be 200, but not sure how to get there. Instead, it's 403. Any help?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
