python3简单实现微信爬虫

yipeiwu_com4年前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爬取最好大学网大学排名

本文实例为大家分享了Python爬取最好大学网大学排名的具体代码,供大家参考,具体内容如下 源代码: #-*-coding:utf-8-*- ''''' Created on...

Python3 实现爬取网站下所有URL方式

获取首页元素信息: 目标 test_URL:http://www.xxx.com.cn/ 首先检查元素,a 标签下是我们需要爬取得链接,通过获取链接路径,定位出我们需要的信息 sou...

Python爬虫框架Scrapy实战之批量抓取招聘信息

Python爬虫框架Scrapy实战之批量抓取招聘信息

网络爬虫抓取特定网站网页的html数据,但是一个网站有上千上万条数据,我们不可能知道网站网页的url地址,所以,要有个技巧去抓取网站的所有html页面。Scrapy是纯Python实现的...

python抓取网站的图片并下载到本地的方法

实例如下所示: #!/usr/bin/python # -*- coding: UTF-8 -*- import re import urllib,urllib2; #通过url获取...

玩转python爬虫之爬取糗事百科段子

玩转python爬虫之爬取糗事百科段子

大家好,前面入门已经说了那么多基础知识了,下面我们做几个实战项目来挑战一下吧。那么这次为大家带来,Python爬取糗事百科的小段子的例子。 首先,糗事百科大家都听说过吧?糗友们发的搞笑的...