In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how python crawls 5646 Zhihu answers, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let the editor take you to understand it.
No bb show your code
Here is the core code display, which mainly passes the question number of Zhihu into the function as a parameter, then crawls the answers in batches, and uses regular expressions to extract the book or movie names that contain the book title in each answer, and finally in the saved csv.
Def getAnswers (qid):
# get all books and answer data
Offset = 0
Book_data = {}
While True:
Qid = qid
Print ('Offset =', offset)
# Zhihu api request
Url = "https://www.zhihu.com/api/v4/questions/{}/answers?include=content&limit=20&offset={}&platform=desktop&sort_by=default".format(
Qid, offset)
Res = requests.get (url, headers=headers)
Res.encoding = 'utf-8'
Data = res.json ()
If len (data ['data']) = = 0:
Break
For line in data ['data']:
# Save answer data
Content = line ['content']
Result = re.findall (r'"(. *?)", content)
For name in result:
Book_ data [name] = book_data.get (name, 0) + 1
Offset + = 20
# Save crawled content
For i in book_data.keys ():
New_data = {}
If i:
New_data ['Book name'] = I
New_data ['Frequency'] = book_ data [I]
Pandas_data.append (new_data)
Df2 = pd.DataFrame (pandas_data, columns= ['Book name', 'Frequency'])
Df2.to_csv ("book.csv", encoding= "utf_8_sig")
Result display
A total of 6434 books were recommended with 5464 responses, of which living was recommended 286 times.
Brother Xing can't help sighing that these bosses with an annual salary of one million have to consider the same problem as Brother Xing-being alive seems to be a step closer to an annual salary of one million. I don't know how many books you are short of your annual salary of $1 million.
If you have read all the top ten books, take a look at the list of the first 11-20 books. If you have read them, you can check the list of 6343 books directly at the end of the article. All of these books can be read for free on Wechat, so you don't have to worry about not finding the pdf version.
Thank you for reading this article carefully. I hope the article "how to python climb 5646 Zhihu answers" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.