'''
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. ubuntu-18.04 设置开机启动脚本-亲测有效

    ubuntu-18.04不能像ubuntu14一样通过编辑rc.local来设置开机启动脚本,通过下列简单设置后,可以使rc.local重新发挥作用. 2.将下列内容复制进rc-local.servi ...

  2. Xapian索引-文档检索过程分析之匹配百分比

    本文属于文档检索过程分析的一部分,重点分析文档匹配百分比(percent)的计算过程. 1 percent是什么? 我们之前分析的检索demo: Xapian::Query term_one = Xa ...

  3. 从壹开始前后端分离 [ Vue2.0+.NET Core2.1] 十七 ║Vue基础:使用Vue.js 来画博客首页+指令(一)

    缘起 书说前两篇文章<十五 ║ Vue前篇:JS对象&字面量&this>和 <十六 ║ Vue前篇:ES6初体验 & 模块化编程>,已经通过对js面向对 ...

  4. Linux知识要点大全(第二章)

    第二章   linux操作系统安装与配置主要内容 1:vmware虚拟机安装与使用 2:Linux系统安装前准备 3:Linux Centos 系统的安装 4:Centos 6.8的登录和关闭 5:C ...

  5. 记一次工作失误,openresty报502错误

    调试落地项目,代理跳转接口报502错误. 一开始认为阿里云tomcat有误,后面发现别的地址代理跳转有效. 开始配置跳转地址,一直折腾半天不好使.后面才知道,应用服务器和数据库服务器是分开部署的.一直 ...

  6. 286万QPS!腾讯云TDSQL打造数据库领域的“超音速战机”

    Bloodhound SSC超音速汽车将陆地极限速度提升到1678公里/小时,号称陆地“超音速战斗机”.无独有偶,同样也在2017年,在英特尔®.腾讯金融云团队的共同见证下,腾讯云数据库TDSQL采用 ...

  7. qml demo分析(threadedanimation-线程动画)

    一.效果预览 使用过qml的同学都知道,使用qml做动画效果是非常简单的,再也不需要像QWidget那样,自己模拟一个动画,费时又费力,往往还达不到效果.今天我们就来分析下qml的两种动画实现方式,如 ...

  8. 异常 - 虚拟机初始化错误 - Error occurred during initialization of VM

    目录 1 环境配置信息 1.1 服务器配置信息 1.2 Tomcat启动参数 2 问题描述 3 问题解决 4 关于vm.overcommit_memory参数 4.1 vm.overcommit_me ...

  9. 前端笔记之移动端&响应式(上)媒体查询&Bootstrap&动画库&zepto&velocity

    一.媒体(介)查询 1.1 基本语法 媒体查询由媒体类型和一个或多个检测媒体特性的条件表达式组成.媒体查询中可用于检测的媒体特性有:width.height和color(等).使用媒体查询可以在不改变 ...

  10. .NET ClrProfiler ILRewrite 商业级APM原理

    Demo:https://github.com/caozhiyuan/ClrProfiler.Trace 背景 为了实现自动.无依赖地跟踪分析应用程序性能(达到商业级APM效果),作者希望能动态修改应 ...