Skip to content

Instantly share code, notes, and snippets.

@dgnsrekt
Created September 5, 2020 01:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgnsrekt/8cdb0c10e4a8fe6dcef65ee3a66a4e33 to your computer and use it in GitHub Desktop.
Save dgnsrekt/8cdb0c10e4a8fe6dcef65ee3a66a4e33 to your computer and use it in GitHub Desktop.
solution from
from requests_html import HTMLSession
from pprint import pprint
from urllib.parse import urlparse
import re
import time
URL = "https://www.twitter.com/"
session = HTMLSession()
resp = session.get(URL)
links = resp.html.find("link")
scripts = []
for link in links:
if link.attrs.get("as") != "script":
continue
scripts.append(link.attrs.get("href"))
time.sleep(5)
pprint(scripts)
main_script = list(filter(lambda u: "/main." in u, scripts))
assert len(main_script) == 1 # raise MainScriptNotFoundError()
new = main_script[0]
resp = session.get(new)
token_regex = re.compile(r"A{20}.{84}")
token = token_regex.findall(resp.text)
assert len(token) == 1
token = f"Bearer {token[0]}"
time.sleep(5)
headers = {"Authorization": token}
activation_url = "https://api.twitter.com/1.1/guest/activate.json"
print(token)
resp = session.post(activation_url, headers=headers)
guest_token = resp.text
headers["x-guest-token"] = resp.text
time.sleep(5)
print(headers)
username = "dgnsrekt"
urlx = f"https://api.twitter.com/graphql/4S2ihIKfF3xhp-ENxvUAfQ/UserByScreenName?variables=%7B%22screen_name%22%3A%22{username}%22%2C%22withHighlightedLabel%22%3Atrue%7D"
resp = session.get(urlx, headers=headers)
pprint(resp.json())
time.sleep(5)
rest_id = "2474416796"
count = 10
urly = (
"https://api.twitter.com/2/timeline/profile/{rest_id}.json"
+ "?include_profile_interstitial_type=1"
+ "&include_blocking=1"
+ "&include_blocked_by=1"
+ "&include_followed_by=1"
+ "&include_want_retweets=1"
+ "&include_mute_edge=1"
+ "&include_can_dm=1"
+ "&include_can_media_tag=1"
+ "&skip_status=1"
+ "&cards_platform=Web-12"
+ "&include_cards=1"
+ "&include_ext_alt_text=true"
+ "&include_quote_count=true"
+ "&include_reply_count=1"
+ "&tweet_mode=extended"
+ "&include_entities=true"
+ "&include_user_entities=true"
+ "&include_ext_media_color=true"
+ "&include_ext_media_availability=true"
+ "&send_error_codes=true"
+ "&simple_quoted_tweet=true"
+ "&include_tweet_replies=false"
+ "&userId={rest_id}"
+ "&count={count}"
+ "&ext=mediaStats%2ChighlightedLabel"
)
resp = session.get(urly, headers=headers)
print(resp.text)
time.sleep(5)
@ReS4
Copy link

ReS4 commented Jan 4, 2021

Error while loading tweets:

{"errors":[{"message":"Rate limit exceeded","code":88}]}

@dgnsrekt
Copy link
Author

dgnsrekt commented Jan 5, 2021

That is the issue I never fixed. Haven't had much time to work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment