Skip to content

Instantly share code, notes, and snippets.

@monk1337
Last active November 25, 2022 16:17
Show Gist options
  • Save monk1337/2de73657c06f543b15711790208a1e5b to your computer and use it in GitHub Desktop.
Save monk1337/2de73657c06f543b15711790208a1e5b to your computer and use it in GitHub Desktop.
import time
NextPage = True
request_count = 0
# endCursor = '5981683117051934905'
endCursor = '9173542013414046873'
multifeed_n = 20
while NextPage:
result = get_questions(multifeed_n = multifeed_n,
endcursor = endCursor)
print(result)
NextPage = result['ipage']['hasNextPage']
endCursor = result['ipage']['endCursor']
multifeed_n+=10
request_count+=1
print("request_count", request_count)
print("\n\n\n\n")
time.sleep(random.randint(5,12))
import requests
from datetime import datetime
import random
import json
import time
cookies = {
'm-b': 'QFncGIoFeSEWiYczzU8Npw==',
'm-b_lax': 'QFncGIoFeSEWiYczzU8Npw==',
'm-b_strict': 'QFncGIoFeSEWiYczzU8Npw==',
'm-s': 'eeDfjDc-QEPVyXxa_tLBMQ==',
'm-dynamicFontSize': 'regular',
'G_ENABLED_IDPS': 'google',
'm-ans_frontend_early_version': '9d4efaf3578d95ce',
'__stripe_mid': '31d91cf3-05c1-47e0-a1b2-cf13611d568ebac2ef',
'm-theme': 'light',
'm-sa': '1',
'g_state': '{"i_p":1655016883763,"i_l":1}',
'_scid': 'eb3c85b7-2443-47f5-a98a-3a91bc98934c',
'_gcl_au': '1.1.11585039.1655010027',
'_fbp': 'fb.1.1655010027457.732862936',
'_sctr': '1|1654972200000',
'm-lat': 'ZsW8sG1mBmSKHTmCpjnoig==',
'm-login': '1',
'm-uid': '323905208',
'__aaxsc': '2',
'aasd': '1%7C1655348471751',
'__cf_bm': '3yw.EGhGuyLU8L3k5ExIWxDi28Sr_wwL0euCDDHeyO4-1655402188-0-ARZn8RhFRBG4Qrvkj3lHUudsUCFz5j63cwWsm1E7b0R/u7ykPqSfO/d6JGwaBG32YlA1yWDH+g5Hufb8LJ4hz/o=',
'__stripe_sid': '0a26c4a0-fa85-4cd1-9799-e663efcf63fb5a576f',
}
headers = {
'Accept': '*/*',
'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8',
'Connection': 'keep-alive',
# Already added when you pass json=
# 'Content-Type': 'application/json',
# Requests sorts cookies= alphabetically
# 'Cookie': 'm-b=QFncGIoFeSEWiYczzU8Npw==; m-b_lax=QFncGIoFeSEWiYczzU8Npw==; m-b_strict=QFncGIoFeSEWiYczzU8Npw==; m-s=eeDfjDc-QEPVyXxa_tLBMQ==; m-dynamicFontSize=regular; G_ENABLED_IDPS=google; m-ans_frontend_early_version=9d4efaf3578d95ce; __stripe_mid=31d91cf3-05c1-47e0-a1b2-cf13611d568ebac2ef; m-theme=light; m-sa=1; g_state={"i_p":1655016883763,"i_l":1}; _scid=eb3c85b7-2443-47f5-a98a-3a91bc98934c; _gcl_au=1.1.11585039.1655010027; _fbp=fb.1.1655010027457.732862936; _sctr=1|1654972200000; m-lat=ZsW8sG1mBmSKHTmCpjnoig==; m-login=1; m-uid=323905208; __aaxsc=2; aasd=1%7C1655348471751; __cf_bm=3yw.EGhGuyLU8L3k5ExIWxDi28Sr_wwL0euCDDHeyO4-1655402188-0-ARZn8RhFRBG4Qrvkj3lHUudsUCFz5j63cwWsm1E7b0R/u7ykPqSfO/d6JGwaBG32YlA1yWDH+g5Hufb8LJ4hz/o=; __stripe_sid=0a26c4a0-fa85-4cd1-9799-e663efcf63fb5a576f',
'Origin': 'https://www.quora.com',
'Quora-Broadcast-Id': 'main-w-chan51-8888-react_fdwzvfgzojvaehdt-tIFD',
'Quora-Canary-Revision': 'false',
'Quora-Formkey': 'ae6918f2c621a57d19f22f9d93bf9cd4',
'Quora-Revision': '8a7d5af5bbb8da559095489a51de039792c50640',
'Quora-Window-Id': 'react_bwuulsbjyhfqbuhv',
'Referer': 'https://www.quora.com/topic/Anatomy-1?q=anato',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="102", "Google Chrome";v="102"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"macOS"',
}
# cookies = {
# 'm-b': 'QFncGIoFeSEWiYczzU8Npw==',
# 'm-b_lax': 'QFncGIoFeSEWiYczzU8Npw==',
# 'm-b_strict': 'QFncGIoFeSEWiYczzU8Npw==',
# 'm-s': 'eeDfjDc-QEPVyXxa_tLBMQ==',
# 'm-dynamicFontSize': 'regular',
# 'G_ENABLED_IDPS': 'google',
# 'm-ans_frontend_early_version': '9d4efaf3578d95ce',
# '__stripe_mid': '31d91cf3-05c1-47e0-a1b2-cf13611d568ebac2ef',
# 'm-theme': 'light',
# 'm-sa': '1',
# 'g_state': '{"i_p":1655016883763,"i_l":1}',
# '_scid': 'eb3c85b7-2443-47f5-a98a-3a91bc98934c',
# '_gcl_au': '1.1.11585039.1655010027',
# '_fbp': 'fb.1.1655010027457.732862936',
# '_sctr': '1|1654972200000',
# 'm-lat': 'ZsW8sG1mBmSKHTmCpjnoig==',
# 'm-login': '1',
# 'm-uid': '323905208',
# '__aaxsc': '2',
# 'aasd': '1%7C1655348471751',
# '__cf_bm': '3hUvluWfnRwM4Kke.xXrx7zOnwuXBzQ2lOlcvoSZBYE-1655404025-0-AarvnI4aRtoVXXs4tPwOT2ho5dA9gfJYo8DDJzLTo6pYSOd1DJVlJ+9eBSZnBJ1rncskpL5hn+EcmaqHnb+zrT4=',
# '__stripe_sid': '1f4dd235-ba51-4112-b8b8-fe06214f67537d8c60',
# }
# headers = {
# 'Accept': '*/*',
# 'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8',
# 'Connection': 'keep-alive',
# # Already added when you pass json=
# # 'Content-Type': 'application/json',
# # Requests sorts cookies= alphabetically
# # 'Cookie': 'm-b=QFncGIoFeSEWiYczzU8Npw==; m-b_lax=QFncGIoFeSEWiYczzU8Npw==; m-b_strict=QFncGIoFeSEWiYczzU8Npw==; m-s=eeDfjDc-QEPVyXxa_tLBMQ==; m-dynamicFontSize=regular; G_ENABLED_IDPS=google; m-ans_frontend_early_version=9d4efaf3578d95ce; __stripe_mid=31d91cf3-05c1-47e0-a1b2-cf13611d568ebac2ef; m-theme=light; m-sa=1; g_state={"i_p":1655016883763,"i_l":1}; _scid=eb3c85b7-2443-47f5-a98a-3a91bc98934c; _gcl_au=1.1.11585039.1655010027; _fbp=fb.1.1655010027457.732862936; _sctr=1|1654972200000; m-lat=ZsW8sG1mBmSKHTmCpjnoig==; m-login=1; m-uid=323905208; __aaxsc=2; aasd=1%7C1655348471751; __cf_bm=3hUvluWfnRwM4Kke.xXrx7zOnwuXBzQ2lOlcvoSZBYE-1655404025-0-AarvnI4aRtoVXXs4tPwOT2ho5dA9gfJYo8DDJzLTo6pYSOd1DJVlJ+9eBSZnBJ1rncskpL5hn+EcmaqHnb+zrT4=; __stripe_sid=1f4dd235-ba51-4112-b8b8-fe06214f67537d8c60',
# 'Origin': 'https://www.quora.com',
# 'Quora-Broadcast-Id': 'main-w-chan51-8888-react_bwuulsbjyhfqbuhv-SmdP',
# 'Quora-Canary-Revision': 'false',
# 'Quora-Formkey': 'ae6918f2c621a57d19f22f9d93bf9cd4',
# 'Quora-Revision': 'e360b8142f434dbc0c8b3830b8a4da0967b0defd',
# 'Quora-Window-Id': 'react_bwuulsbjyhfqbuhv',
# 'Referer': 'https://www.quora.com/topic/Anatomy-1?q=anato',
# 'Sec-Fetch-Dest': 'empty',
# 'Sec-Fetch-Mode': 'cors',
# 'Sec-Fetch-Site': 'same-origin',
# 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36',
# 'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="102", "Google Chrome";v="102"',
# 'sec-ch-ua-mobile': '?0',
# 'sec-ch-ua-platform': '"macOS"',
# }
def questions(response):
ihash = [k['node']['stories'][0]['ad']['impressionHash']
for k in response.json()['data']['multifeedObject']['multifeedConnection']['edges']
if 'ad' in k['node']['stories'][0]]
ques = sorted([k['node']['stories'][0]['answer']['question']['url']
for k in response.json()['data']['multifeedObject']['multifeedConnection']['edges']
if 'answer' in k['node']['stories'][0]])
ipage= response.json()['data']['multifeedObject']['multifeedConnection']['pageInfo']
return {'ihas': ihash, 'ques': ques, 'ipage': ipage}
def time_conversion():
time_now = datetime.now().strftime("%s%f")
first = list(time_now)[:-3]
second = ['0','0','0']
first.extend(second)
time.sleep(1)
return int("".join(first))
def get_questions(multifeed_n = 10,
endcursor = '6500760295968955138'):
params = {
'q': 'MultifeedQuery',
}
json_data = {
'queryName': 'MultifeedQuery',
'extensions': {
'hash': '9c92f403a680776924762a1964cdbad6a7b9b3e1ec0c2e475c834305722533b9',
},
'variables': {
'first': 10,
'multifeedAfter': endcursor,
'multifeedNumBundlesOnClient': multifeed_n,
'injectionType': None,
'injectionData': None,
'filterStoryType': None,
'filterStoryOid': None,
'multifeedPage': 'topic',
'pageData': 8536,
'showLiveBanner': False,
},
}
response = requests.post('https://www.quora.com/graphql/gql_para_POST', params=params, cookies=cookies, headers=headers, json=json_data, verify = False)
# time.sleep(random.randint(5,10))
result = questions(response)
return result
def post_data(impress_hash1,
impress_hash2):
if impress_hash1 and impress_hash2:
data = {
'revision': '16a57bd6f402160a6229237320502d08bff6b8d4',
'postkey': 'e733f15dd08959524f6bd3924f5aad26',
'is_canary_revision': 'false',
'formkey': 'ae6918f2c621a57d19f22f9d93bf9cd4',
'window_id': 'react_uyuvvamjlvjhbuee',
'referring_controller': 'topic',
'referring_action': 't',
'json': json.dumps({"args":[],"kwargs":{"messages":[{"category":"feed_paging","data":{"event":"true_finish","framework":"react","multifeedPage":13,"readyToLoadMore": True},"time":time_conversion()},
{"category":"action_log","data":{"type":38,"hash":impress_hash1,"ads_action_primary":"on_client"},"time":time_conversion()},
{"category":"home_feed_answer_gen","data":{"framework":"react","event":"question_feed_story_rendered"},"time":time_conversion()},
{"category":"action_log","data":{"type":38,"hash":impress_hash2,"ads_action_primary":"on_client"},"time":time_conversion()}],"nid":0}}),
}
response = requests.post('https://www.quora.com/ajax/receive_POST', cookies=cookies, headers=headers, data=data, verify = False)
else:
data = {
'revision': '8a7d5af5bbb8da559095489a51de039792c50640',
'postkey': 'afdd02b9bc5135370ffd27f04f3dfb1c',
'is_canary_revision': 'false',
'formkey': 'ae6918f2c621a57d19f22f9d93bf9cd4',
'window_id': 'react_fdwzvfgzojvaehdt',
'referring_controller': 'topic',
'referring_action': 't',
'json': json.dumps({"args":[],"kwargs":{"messages":[{"category":"feed_paging","data":{"event":"true_finish","framework":"react","multifeedPage":13,"readyToLoadMore": True},"time":time_conversion()},
{"category":"home_feed_answer_gen","data":{"framework":"react","event":"question_feed_story_rendered"},"time":time_conversion()}],"nid":0}}),
}
response = requests.post('https://www.quora.com/ajax/receive_POST', cookies=cookies, headers=headers, data=data, verify = False)
time.sleep(3)
return response.json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment