python3简单实现微信爬虫

yipeiwu_com5年前Python爬虫

使用ghost.py 通过搜搜 的微信搜索来爬取微信公共账号的信息

# -*- coding: utf-8 -*-
import sys
reload(sys)
import datetime
import time
sys.setdefaultencoding("utf-8")
 
from ghost import Ghost
ghost = Ghost(wait_timeout=20)
 
url="http://weixin.sogou.com/gzh?openid=oIWsFt8JDv7xubXz5E3U41T0eFbk"
page,resources = ghost.open(url)
result, resources = ghost.wait_for_selector("#wxmore a")
 
from bs4 import BeautifulSoup
c=0
while True:
  if c>=30:
    break
 
  soup = BeautifulSoup(ghost.content)
 
  for wx in soup.find_all("h4"):
    print wx
 
  page, resources = ghost.evaluate(
    """
    var div1 = document.getElementById("wxbox");
    div1.innerHTML = '';
    """)
  ghost.click("#wxmore a")
  result, resources = ghost.wait_for_selector(".wx-rb3")
 
  c=c+1
  pass

以上所述就是本文的全部内容了,希望对大家学习Python能够有所帮助

相关文章

python爬虫 猫眼电影和电影天堂数据csv和mysql存储过程解析

字符串常用方法 # 去掉左右空格 'hello world'.strip() # 'hello world' # 按指定字符切割 'hello world'.split(' ')...

Python3直接爬取图片URL并保存示例

有时候我们会需要从网络上爬取一些图片,来满足我们形形色色直至不可描述的需求。 一个典型的简单爬虫项目步骤包括两步:获取网页地址和提取保存数据。 这里是一个简单的从图片url收集图片的例子...

Python爬取三国演义的实现方法

本文的爬虫教程分为四部:      1.从哪爬 where      2.爬什么 what  &...

python正则爬取某段子网站前20页段子(request库)过程解析

python正则爬取某段子网站前20页段子(request库)过程解析

首先还是谷歌浏览器抓包对该网站数据进行分析,结果如下: 该网站地址:http://www.budejie.com/text 该网站数据都是通过html页面进行展示,网站url默认为第...

零基础写python爬虫之HTTP异常处理

先来说一说HTTP的异常处理问题。当urlopen不能够处理一个response时,产生urlError。不过通常的Python APIs异常如ValueError,TypeError等也...