• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python 爬取微信文章

python 爬取微信文章

作者:hebedich 字体:[增加 减小] 来源:互联网

hebedich 通过本文主要向大家介绍了python爬文章,python爬取文章,python文章,python爬取微信,爬取微信公众号文章等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本人想搞个采集微信文章的网站,无奈实在从微信本生无法找到入口链接,网上翻看了大量的资料,发现大家的做法总体来说大同小异,都是以搜狗为入口。下文是笔者整理的一份python爬取微信文章的代码,有兴趣的欢迎阅读

#coding:utf-8
author = 'haoning'
**#!/usr/bin/env python
import time
import datetime
import requests**
import json
import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )
import re
import xml.etree.ElementTree as ET
import os
#OPENID = 'oIWsFtyel13ZMva1qltQ3pfejlwU'
OPENID = 'oIWsFtw_-W2DaHwRz1oGWzL-wF9M&ext'
XML_LIST = []
# get current time in milliseconds
current_milli_time = lambda: int(round(time.time() * 1000))
def get_json(pageIndex):

global OPENID
the_headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36',
'Referer': 'http://weixin.sogou.com/gzh?openid={0}'.format(OPENID),
'Host': 'weixin.sogou.com'
}

url = 'http://weixin.sogou.com/gzhjs?cb=sogou.weixin.gzhcb&openid={0}&page={1}&t={2}'.format(OPENID, pageIndex, current_milli_time()) #url
print(url)

response = requests.get(url, headers = the_headers)
# TO-DO; check if match the reg
response_text = response.text
print response_text
json_start = response_text.index('sogou.weixin.gzhcb(') + 19
json_end = response_text.index(')') - 2
json_str = response_text[json_start : json_end] #get json
#print(json_str)
# convert json_str to json object
json_obj = json.loads(json_str) #get json obj
# print json_obj['totalPages']
return json_obj
def add_xml(jsonObj):

global XML_LIST
xmls = jsonObj['items'] #get item
#print type(xmls)
XML_LIST.extend(xmls) #用新列表扩展原来的列表
**[#www.oksousou.com][2]**
# ------------ Main ----------------
print 'play it :) '
# get total pages
default_json_obj = get_json(1)
total_pages = 0
total_items = 0
if(default_json_obj):

# add the default xmls
add_xml(default_json_obj)
# get the rest items
total_pages = default_json_obj['totalPages']
total_items = default_json_obj['totalItems']
print total_pages
# iterate all pages
if(total_pages >= 2):
  for pageIndex in range(2, total_pages + 1):
    add_xml(get_json(pageIndex)) #extend
    print 'load page ' + str(pageIndex)
    print len(XML_LIST)
</div>

</div>

您可能想查找下面的文章:

  • python 爬取微信文章
  • 一篇文章入门Python生态系统(Python新手入门指导)
  • 一篇文章入门Python生态系统(Python新手入门指导)
  • Python实现提取文章摘要的方法
  • 简单使用Python自动生成文章

相关文章

  • Python简单进程锁代码实例
  • python字符类型的一些方法小结
  • python脚本监控docker容器
  • Python的装饰器用法学习笔记
  • Python黑魔法@property装饰器的使用技巧解析
  • python根据出生年份简单计算生肖的方法
  • Python中functools模块的常用函数解析
  • 使用Python进行二进制文件读写的简单方法(推荐)
  • Python中的列表知识点汇总
  • Python Socket编程入门教程

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python利用Nagios增加微信报警通知的功能
    • 一键搞定python连接mysql驱动有关问题(windows版本)
    • 在Python中测试访问同一数据的竞争条件的方法
    • Python socket编程实例详解
    • 详解在Python程序中自定义异常的方法
    • Python时间戳与时间字符串互相转换实例代码
    • 从零学python系列之从文件读取和保存数据
    • php使用递归与迭代实现快速排序示例
    • 在Mac OS系统上安装Python的Pillow库的教程
    • Python 绘图和可视化详细介绍

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有