Beispiel #1
0
# coding=utf-8

from __future__ import unicode_literals, print_function

import os

from zhihu_oauth import ZhihuClient

TOKEN_FILE = 'token.pkl'

client = ZhihuClient()

if os.path.isfile(TOKEN_FILE):
    client.load_token(TOKEN_FILE)
else:
    client.login_in_terminal()
    client.save_token(TOKEN_FILE)

author = client.from_url('http://www.zhihu.com/people/liang-qi-ying-xiang')
print(author.following_topics)
        T_QUESTIONS_COUNT TEXT NOT NULL);
        ''')

# posturl
SUMMARY_URL = 'http://api.bosonnlp.com/summary/analysis'
SENTIMENT_URL = 'http://api.bosonnlp.com/sentiment/analysis'

# X-Token
headers = {'X-Token': 'afA7ckHA.7771.3EQV8MutdTWw'}

client = ZhihuClient()
client.load_token('token.pkl')
# replace it  as user input

# topic
internet = client.from_url('https://www.zhihu.com/topic/19550517')
political = client.from_url('https://www.zhihu.com/topic/19551424')
computer = client.from_url('https://www.zhihu.com/topic/19555547')
occupation = client.from_url('https://www.zhihu.com/topic/19552488')
fishing = client.from_url('https://www.zhihu.com/topic/20022251')
society = client.from_url('https://www.zhihu.com/topic/19566933')

# internet

print(internet.id)
print(internet.best_answers_count)
print(internet.followers_count)
print(internet.questions_count)

conn.execute(
            "INSERT INTO TOPIC_TABLE (T_ID, T_BEST_ANSWERS_COUNT, T_FOLLOWERS_COUNT, T_QUESTIONS_COUNT) \
from __future__ import print_function
from zhihu_oauth import ZhihuClient
from zhihu_oauth.exception import NeedCaptchaException

client = ZhihuClient()

try:
    client.login('邮箱或电话', '密码')
    # 使用手机号登录需要在手机号前加 +86 前缀
except NeedCaptchaException:
    # 保存验证码并提示输入,输入gif所示验证码进行登录
    with open('a.gif', 'wb') as f:
        f.write(client.get_captcha())
    captcha = input('please input captcha:')
    client.login('邮箱或电话', '密码', captcha)

article = client.from_url('https://zhuanlan.zhihu.com/p/25671089')
# 随意改知乎链接,自动识别

print(article.author.name)
print(article.voteup_count)
result = ''
for i in article.comments:
    j = i.author.name + '\n'
    result += j

f = open('E:\GitHouse\zhihu-oauth\jilu4.txt', 'w')
f.write(result)
f.close()
# 写入文档,可改用with open('E:\GitHouse\zhihu-oauth\jilu4.txt','a',encoding='utf-8') as f
Beispiel #4
0


db_connection = sql.connect(host='localhost', db='zhihu', user='******', passwd='123', charset = 'utf8')
cur=db_connection.cursor() 
sql = "insert into final values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"

df = pd.read_sql('SELECT distinct * FROM user', con=db_connection)



for i in range(400009,700000):
    randomTime = random.uniform(1,2) 
    time.sleep(randomTime) 
    url = 'http://www.zhihu.com/people/' + df['user_token'][i]
    author = client.from_url(url)
    try:
      topic = author.following_topics
    except:
      pass
    j = 0
    for t in topic:
        j = j + 1
        if(j == 1):
            df['topic1'][i] = t.name
        elif(j == 2):
            df['topic2'][i] = t.name
        elif(j == 3):
            df['topic3'][i] = t.name   
        elif(j == 4):
            df['topic4'][i] = t.name
        ''')

# posturl
SUMMARY_URL = 'http://api.bosonnlp.com/summary/analysis'
SENTIMENT_URL = 'http://api.bosonnlp.com/sentiment/analysis'
CLASSIFY_URL = 'http://api.bosonnlp.com/classify/analysis'

# X-Token
headers = {'X-Token': 'afA7ckHA.7771.3EQV8MutdTWw'}

client = ZhihuClient()
client.load_token('token.pkl')
# replace it  as user input

# topic
internet = client.from_url('https://www.zhihu.com/topic/19550517')
sport = client.from_url('https://www.zhihu.com/topic/19554827')
education = client.from_url('https://www.zhihu.com/topic/19553176')
bussiness = client.from_url('https://www.zhihu.com/topic/19555457')
society = client.from_url('https://www.zhihu.com/topic/19566933')
entertain = client.from_url('https://www.zhihu.com/topic/19553632')
military = client.from_url('https://www.zhihu.com/topic/19553911')
nation = client.from_url('https://www.zhihu.com/topic/19553911')
science = client.from_url('https://www.zhihu.com/topic/19556664')
realestate = client.from_url('https://www.zhihu.com/topic/19555559')
international = client.from_url('https://www.zhihu.com/topic/19561759')
female = client.from_url('https://www.zhihu.com/topic/19556945')
automoile = client.from_url('https://www.zhihu.com/topic/19551915')
game = client.from_url('https://www.zhihu.com/topic/19550994')

# internet