Created
February 8, 2023 08:45
-
-
Save riceissa/9e327d3de3f49624b2d60086d237af32 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
#!/usr/bin/env python3 | |
import requests | |
query = """ | |
{ | |
posts(input: { | |
terms: { | |
view: "top" | |
limit: 50 | |
meta: null | |
} | |
}) { | |
results { | |
_id | |
title | |
} | |
} | |
} | |
""" | |
# request made without setting a user agent; defaults to 'python-requests/2.28.1' | |
r1 = requests.get("https://www.lesswrong.com/graphql", params={'query': query}) | |
# request made using a typical browser's user agent | |
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0" | |
r2 = requests.get("https://www.lesswrong.com/graphql", params={'query': query}, headers={'User-Agent': user_agent}) | |
print(r1.status_code) # prints 403 | |
print(r2.status_code) # prints 200 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment