'''
Created on 2018-5-27 @author: yaoshuangqi
'''
#本代码获取百度乐彩网站上的信息,只获取最近100期的双色球
import urllib.request
from bs4 import BeautifulSoup
import random ere_hitlist = []
hitlist = []
def getSSQ100():
#site = 'http://trend.lecai.com/ssq/redBaseTrend.action?recentPhase=100&onlyBody=false&phaseOrder=up&coldHotOrder=number'
site ='https://www.17500.cn/ssq/'
page = urllib.request.urlopen(site)
html = page.read().decode('gb18030');#注意编码
print(html)
soup = BeautifulSoup(html,"html.parser")#指定html解析器 hhlist = soup.find_all("td",class_="red_ball")
bluelist = soup.find_all("td",class_="blue_ball") num = 0
count = 0
for tag in hhlist:
global hitlist
global ere_hitlist
if num < 6:
hitlist.append(tag.contents[0])
if count == 599:
ere_hitlist.append(hitlist)
hitlist = []
elif num == 6 :
ere_hitlist.append(hitlist)
hitlist = []
num = 0
hitlist.append(tag.contents[0])
num+=1
count+=1
num = 0
for sublist in ere_hitlist:
sublist.append(bluelist[num].contents[0])
num+=1 def chooseSSQ():
hhlist = []
lhlist = []
ylhlist = ['','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','']
ylllist = ['','','','','','','','','','','','','','','','']
ylhrlist = []
yllrlist = []
num = 0
for curlist in ere_hitlist:
for value in curlist:
num+=1
for ylval in ylhlist:
if ylval == value and len(curlist) == num:
yllrlist.append(value)
elif ylval == value and len(curlist) != num:
ylhrlist.append(value)
num = 0
print("红号:",len(ylhrlist),"蓝号:",len(yllrlist)) if len(ylhrlist) == 600 and len(yllrlist) == 100:
lh = random.randint(0,99)
lhlist.append(ere_hitlist[lh][6]) while len(hhlist) < 6:
hh = random.randint(0,99)
hhs = random.randint(0,5)
hhlist.append(ere_hitlist[hh][hhs])
hhlist = list(set(hhlist)) elif len(ylhrlist) == 600 and len(yllrlist) != 100:
lh = random.randint(0,len(yllrlist))
lhlist.append(yllrlist[lh])
lh = random.randint(0,15)
lhlist.append(ylllist[lh]) while len(hhlist) < 6:
hh = random.randint(0,99)
hhs = random.randint(0,5)
hhlist.append(ere_hitlist[hh][hhs])
hhlist = list(set(hhlist)) elif len(ylhrlist) != 600 and len(yllrlist) == 100:
lh = random.randint(0,99)
lhlist.append(lh) while len(hhlist) < 3:
hh = random.randint(0,len(ylhrlist))
hhlist.append(ylhrlist[hh])
hhlist = list(set(hhlist)) while len(hhlist) < 6:
hh = random.randint(0,len(ylhlist))
hhlist.append(ylhlist[hh])
hhlist = list(set(hhlist)) elif len(ylhrlist) != 600 and len(yllrlist) != 100:
lh = random.randint(0,len(yllrlist))
lhlist.append(yllrlist[lh])
lh = random.randint(0,15)
lhlist.append(ylllist[lh]) while len(hhlist) < 3:
hh = random.randint(0,len(ylhrlist))
hhlist.append(ylhrlist[hh])
hhlist = list(set(hhlist)) while len(hhlist) < 6:
hh = random.randint(0,len(ylhlist))
hhlist.append(ylhlist[hh])
hhlist = list(set(hhlist)) print("根据前100期双色球中奖号码,本人预测下一期中奖号码是,红号:",hhlist,",蓝号:",lhlist) if __name__ == '__main__':
getSSQ100()
chooseSSQ()

使用python抓取数据之菜鸟爬虫1的更多相关文章

  1. python抓取数据 常见反爬虫 情况

    1.报文头信息: User-Agent Accept-Language  防盗链 上referer 随机生成不同的User-Agent构造报头 2.加抓取等待时间 每抓取一页都让它随机休息几秒,加入此 ...

  2. python抓取数据,python使用socks代理抓取数据

    在python中,正常的抓取数据直接使用urllib2 这个模块: import urllib2 url = 'http://fanyi.baidu.com/' stream = urllib2.ur ...

  3. 在mac下使用python抓取数据

    2015已经过去,这是2016的第一篇博文! 祝大家新年快乐! 但是我还有好多期末考试! 还没开始复习,唉,一把辛酸泪! 最近看了一遍彦祖的文章叫做 iOS程序员如何使用Python写网路爬虫 所以自 ...

  4. python抓取数据构建词云

    1.词云图 词云图,也叫文字云,是对文本中出现频率较高的"关键词"予以视觉化的展现,词云图过滤掉大量的低频低质的文本信息,使得浏览者只要一眼扫过文本就可领略文本的主旨. 先看几个词 ...

  5. python 抓取数据,pandas进行数据分析并可视化展示

    感觉要总结总结了,希望这次能写个系列文章分享分享心得,和大神们交流交流,提升提升. 因为半桶子水的水平,一直在想写什么,为什么写,怎么写. 直到现在找到了一种好的办法: 1.写什么 自己手上掌握的,工 ...

  6. python 抓取数据 存入 excel

    import requestsimport datetimefrom random import choicefrom time import timefrom openpyxl import loa ...

  7. Python 抓取数据存储到Mysql中

    # -*- coding: utf-8 -*- import os,sys import requests import bs4 import pymysql#import MySQLdb #连接MY ...

  8. Python 抓取数据存储到Redis中

    redis是一个key-value存储结构.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted set ...

  9. 使用python抓取并分析数据—链家网(requests+BeautifulSoup)(转)

    本篇文章是使用python抓取数据的第一篇,使用requests+BeautifulSoup的方法对页面进行抓取和数据提取.通过使用requests库对链家网二手房列表页进行抓取,通过Beautifu ...

随机推荐

  1. .NET Core微服务之基于Ocelot+IdentityServer实现统一验证与授权

    Tip: 此篇已加入.NET Core微服务基础系列文章索引 一.案例结构总览 这里,假设我们有两个客户端(一个Web网站,一个移动App),他们要使用系统,需要通过API网关(这里API网关始终作为 ...

  2. ProgressWheelDialogUtil【ProgressWheel Material样式进度条对话框】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 简单封装网络请求时的加载对话框以及上传.下载文件的进度加载对话框. 效果图 代码分析 ProgressWheel : 自定义view ...

  3. 『练手』004 Laura.SqlForever如何扩展 导航栏 工具栏 右键菜单 插件

    004 Laura.SqlForever如何扩展 导航栏 工具栏 右键菜单 插件 导航栏 插件扩展 比如下图的    窗口 > 关闭所有文档    这个导航栏: 在 任何程序集,任何命名空间,任 ...

  4. Matlab图像处理常用基本函数

    之前用Matlab做图像处理工作时,用到什么函数就查什么函数,从没做过系统的总结,再做的时候又要去查,所以总结还是有必要的~ 为了方便,在此只列出函数名和基本用法,如不特别指出,不详细说明参数,辅助h ...

  5. html 和css 效果--整理集合篇

    一.如何用一张图片做背景图,并且图片自适应div的大小 background: url("../stu_wengu.png") center center no-repeat; b ...

  6. Python编程从入门到实践笔记——文件

    Python编程从入门到实践笔记——文件 #coding=gbk #Python编程从入门到实践笔记——文件 #10.1从文件中读取数据 #1.读取整个文件 file_name = 'pi_digit ...

  7. Redis入门简述

    Redis 是一个开源的,使用 ANSI C (C语言)编写,高性能的 Key-Value(键值对) 的 NoSQL 数据库 NoSQL = Not Only SQL,意即“不仅仅是SQL”,是一项全 ...

  8. DataTable克隆行

    DataRow Adr = ds.Tables[].NewRow(); Adr.ItemArray = (].Rows[].ItemArray.Clone(); ds.Tables[].Rows.Ad ...

  9. 阿里巴巴矢量图标库(Iconfont)-利于UI和前端的搭配

    前端时间,做一个小网站的时候,需要用到很多小图标,UI设计好之后不知道如何使用,如果使用图片那会很麻烦,相信一些前端更喜欢iconfont这样的标签直接调用,这样包括颜色和大小以及使用都更方便快捷,于 ...

  10. C#中USB转串口的拔插捕获

    // usb消息定义 public const int WM_DEVICE_CHANGE = 0x219; public const int DBT_DEVICEARRIVAL = 0x8000; p ...