实践中学python:刷简书阅读量
2017-08-20 本文已影响748人
十一岁的加重
# coding=utf-8
import random
import os
import re
import requests
# 刷一文章的阅读量
def refreshArticle(articleUrlString):
# 参数 http://www.jianshu.com/p/3487b28de901
# randomStr = random.choice(strings)
while 1==1:
articleIDString = articleUrlString.replace('http://www.jianshu.com/p/', '')
cmd = '''curl 'http://www.jianshu.com/notes/bcb19fe43909/mark_viewed.json' -H 'Cookie: read_mode=day; default_font=font2; gr_user_id=3c07e1eb-4fe7-48f1-a10b-67db4425ef3e; signin_redirect=http%3A%2F%2Fwww.jianshu.com%2Fp%2Fbcb19fe43909; __utma=194070582.964007008.1470540255.1470541535.1470541535.22; __utmc=194070582; __utmz=194070582.1470540255.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmv=194070582.|2=User%20Type=Visitor=1; _session_id=YWZEZ0VkM25jSVBXM3I5NWxoOVRzVGkwa0dKOHhPVlk4T1g0ZVZHYWZVa1VzNkhLMnE1SkNlTldhZ2NudEVqZkk5ODNYRjdiVWZjSnQrSk9GWkYvSlRkck9hQ3ZEd3phNktjN0wyK2ZjWjRpK1BGOFFwRURwRVh1ckd4UVg1Z1B2N0xEY0JjSXNHZW9KTXhQenhxaWd4ZmM5UHJVcEZMVTAySUkzZisySnBhQjdFaHNIU3J6VG9rUHZQMHg5WXBsWG0rWGRPMXh3RXhIYkJsQTZFSmVEV0gwS1o5TllLOEl0NnRBazZOdGR5elNLb1QwQVU1NTIxeURIdjlrMlYrQlVPUU5CSWxYV29oTzNRc0RMZEN3SXJONUFnNnJwWlNkdmxEcVZCajNDWFYxQ1NPVFAzdVB1bnZUaDdlcDBzRlZyS0NBWmZzL1Myc2lhajBTczRrY0tVOUdiYmkySW5CM0w5UE1oSlhGNytZbVhOQWRmaWhWOXVQM0ZsbkRFUDM0bW5NUkFNc0I5RmFySmIzWmV2dUVZUT09LS10VnFmeE5zbDM4Kzl4NUk3MmdlWWhnPT0%3D--1c74458db9cddb6706cd28f8a7713a0eb87103df' -H 'Origin: http://www.jianshu.com' -H 'Accept-Encoding: gzip, deflate' -H 'X-CSRF-Token: saUjkCEJAYqjLjgZxxN1l0kKLvUFNbZKBFJcrEoIOIZR/7QNh9t6VC2JbC4c9V2yX3IKSioKTbF3ekawwkNQaA==' -H 'Accept-Language: zh-CN,zh;q=0.8,en;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Accept: */*' -H 'Cache-Control: max-age=0' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'Referer: http://www.jianshu.com/p/bcb19fe43909' --data 'uuid=24661801-f208-4d73-9ed6-a935ed74e241&referrer=http%3A%2F%2Fwww.jianshu.com%2Fusers%2F6ee0da8f2e57%2Flatest_articles' --compressed'''
cmd = cmd.replace('bcb19fe43909', articleIDString)
print articleIDString
try:
os.system(cmd)
except:
pass
# 调用
#refreshArticle('http://www.jianshu.com/p/3487b28de901')
# 刷一用户的所有文章的阅读量
def refreshUserAllArticle(localHtmlFilePath):
with open(r'%s'%localHtmlFilePath, "r") as f:
page = f.read()
articleIDStrings = re.findall('<a class="title" target="_blank" href="http://www.jianshu.com/p/(.*?)">',page,re.S)
for articleIDString in articleIDStrings:
refreshArticle(articleIDString)
# 调用
#refreshUserAllArticle('/Users/dfpo/Desktop/test.htm')