傻逼知乎

鉴于知乎经常会无缘无故的删除我的一些提问和回答,但是并没有给出明确的原因,因此为了抵制这个傻逼知乎,我决定删除自己在知乎上面的全部回答,截止到我删除之前,我在知乎回答了192条问题,提问了46个问题。
使用自己好几年没有碰的python写的脚本,仓库地址:https://github.com/rollenholt/fuck_zhihu 不算太长,就粘贴在这里吧:

import time
from http import cookiejar
import requests
from bs4 import BeautifulSoup
## 你的知乎登录邮箱
ZHIHU_ENAIL=""
## 你的知乎登录密码
ZHIHU_PASSWORD=""
## 你的知乎用户名,在你主页地址栏可以看到,比如https://www.zhihu.com/people/rollenholt/activities,用户名为rollenholt
ZHIHU_USERNAME=""
headers = {
    "Host": "www.zhihu.com",
    "Referer": "https://www.zhihu.com/",
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
    "Accept-Encoding": "gzip, deflate, sdch, br",
    "Upgrade-Insecure-Requests": "1",
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'
}
session = requests.session()
session.cookies = cookiejar.LWPCookieJar(filename='cookies.txt')
try:
    print(session.cookies)
    session.cookies.load(ignore_discard=True)
except:
    print("还没有cookie信息")
def get_xsrf():
    response = session.get("https://www.zhihu.com", headers=headers)
    soup = BeautifulSoup(response.content, "html.parser")
    xsrf = soup.find('input', attrs={"name": "_xsrf"}).get("value")
    return xsrf
def get_captcha():
    t = str(int(time.time() * 1000))
    captcha_url = 'https://www.zhihu.com/captcha.gif?r=' + t + "&type=login"
    r = session.get(captcha_url, headers=headers)
    with open('captcha.jpg', 'wb') as f:
        f.write(r.content)
    captcha = input("请手动输入当前文件夹下面的验证码:")
    return captcha
def login(email, password):
    login_url = 'https://www.zhihu.com/login/email'
    data = {
        'email': email,
        'password': password,
        '_xsrf': get_xsrf(),
        "captcha": get_captcha(),
        'remember_me': 'true'}
    response = session.post(login_url, data=data, headers=headers)
    login_code = response.json()
    print(login_code['msg'])
    for i in session.cookies:
        print(i)
    session.cookies.save()
def answers():
    answer_ids = []
    answers_url = "https://www.zhihu.com/api/v4/members/" + ZHIHU_USERNAME + "/answers"
    response = session.get(answers_url, headers=headers)
    response_json = response.json()
    paging = response_json['paging']
    totals = paging['totals']
    is_end = paging['is_end']
    print("你一共有" + str(totals) + "条回答.")
    data = response_json['data']
    if data:
        answer_ids =  for answer in data]
    while not is_end:
        answers_url = paging['next']
        response = session.get(answers_url, headers=headers)
        response_json = response.json()
        paging = response_json['paging']
        is_end = paging['is_end']
        data = response_json['data']
        if data:
            answer_ids = answer_ids +  for answer in data]
    return answer_ids
def questions():
    question_ids = []
    question_url = "https://www.zhihu.com/api/v4/members/" + ZHIHU_USERNAME + "/questions"
    response = session.get(question_url, headers=headers)
    response_json = response.json()
    paging = response_json['paging']
    totals = paging['totals']
    is_end = paging['is_end']
    print("你一共有" + str(totals) + "条提问.")
    data = response_json['data']
    if data:
        question_ids =  for question in data]
    while not is_end:
        question_url = paging['next']
        response = session.get(question_url, headers=headers)
        response_json = response.json()
        paging = response_json['paging']
        is_end = paging['is_end']
        data = response_json['data']
        if data:
            question_ids = question_ids +  for question in data]
    return question_ids
def delete_answer():
    answer_delete_url_prefix = "https://www.zhihu.com/api/v4/answers/"
    answer_ids = answers()
    for answerId in answer_ids:
        answer_delete_url = answer_delete_url_prefix + str(answerId)
        response = session.delete(answer_delete_url, headers=headers)
        print(response)
    print("你的全部回答已经删除完毕")
def delete_questions():
    question_ids = questions()
    for questionId in question_ids:
        question_delete_url = "https://www.zhihu.com/api/v4/questions/" + str(questionId) + "/anonyms"
        session.post(question_delete_url, headers=headers)
    print("你的全部提问都已经设置为匿名提问")
if __name__ == '__main__':
    login(ZHIHU_ENAIL, ZHIHU_PASSWORD)
    delete_answer()
    delete_questions()
本文版权归作者所有,禁止一切形式的转载,复制等操作
赞赏

微信赞赏支付宝赞赏

One reply to 傻逼知乎

  1. 楼主别冲动啊,也许有些人就是需要你的回答来解决难题呢

发表评论

电子邮件地址不会被公开。 必填项已用*标注