此脚本将打印页面上找到的所有答案/url。还有无限滚动发出 POST 请求,https://www.quora.com/graphql/gql_para_POST?q=UserProfileAnswersMostRecent_RecentAnswers_Query
但我无法从中获取数据(您可以在开发人员工具 -> 网络选项卡中看到它):
import re
import json
import requests
url = 'https://www.quora.com/profile/Nana-Bello-Shehu/answers'
html_data = requests.get(url).text
d = re.findall(r'window\.ansFrontendGlobals\.data\.inlineQueryResults\.results\[".*?"\] = ("{.*}");', html_data)[-1]
d = json.loads(json.loads(d));
for e in d['data']['user']['recentPublicAndPinnedAnswersConnection']['edges']:
if e['node']['__typename'] != 'Answer':
continue
q = json.loads(e['node']['question']['title'])
title = q['sections'][0]['spans'][0]['text']
u = 'https://www.quora.com' + e['node']['question']['url']
print('{:<90} {}'.format(title, u))
印刷:
Do pictures speak louder than words? https://www.quora.com/Do-pictures-speak-louder-than-words
Does true love exist? https://www.quora.com/Does-true-love-exist-8
What picture made your blood boil? https://www.quora.com/What-picture-made-your-blood-boil
What are the before and after pics of people who are drug addicts for several years? https://www.quora.com/What-are-the-before-and-after-pics-of-people-who-are-drug-addicts-for-several-years
What was the funniest thing you saw/heard today? https://www.quora.com/What-was-the-funniest-thing-you-saw-heard-today
Are there any truly selfless acts, motives, or people? https://www.quora.com/Are-there-any-truly-selfless-acts-motives-or-people
Which famous person in history who is idolized, was actually a horrible person? https://www.quora.com/Which-famous-person-in-history-who-is-idolized-was-actually-a-horrible-person
What is something that you read recently and is worth sharing? https://www.quora.com/What-is-something-that-you-read-recently-and-is-worth-sharing
How do I get the attention of my crush? https://www.quora.com/How-do-I-get-the-attention-of-my-crush
What are some heart touching stories of best friends? https://www.quora.com/What-are-some-heart-touching-stories-of-best-friends