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爬虫抓取豆瓣电影TOP100及用户头像的方法

抓取豆瓣电影TOP100 一、分析豆瓣top页面,构建程序结构 1.首先打开网页http://movie.douban.com/top250?start,也就是top页面 然后试...

python网络爬虫之如何伪装逃过反爬虫程序的方法

有的时候,我们本来写得好好的爬虫代码,之前还运行得Ok, 一下子突然报错了。 报错信息如下: Http 800 Internal internet error 这是因为你的对象网站设置了...

Python 抓取动态网页内容方案详解

Python 抓取动态网页内容方案详解

用Python实现常规的静态网页抓取时,往往是用urllib2来获取整个HTML页面,然后从HTML文件中逐字查找对应的关键字。如下所示: 复制代码 代码如下: import urlli...

Python爬虫获取图片并下载保存至本地的实例

1、抓取煎蛋网上的图片。 2、代码如下: import urllib.request import os #to open the url def url_open(url): r...

Python实现爬取百度贴吧帖子所有楼层图片的爬虫示例

Python实现爬取百度贴吧帖子所有楼层图片的爬虫示例

本文实例讲述了Python实现爬取百度贴吧帖子所有楼层图片的爬虫。分享给大家供大家参考,具体如下: 下载百度贴吧帖子图片,好好看 python2.7版本: #coding=utf-...