使用python抓取数据之菜鸟爬虫1
'''
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的更多相关文章
- python抓取数据 常见反爬虫 情况
1.报文头信息: User-Agent Accept-Language 防盗链 上referer 随机生成不同的User-Agent构造报头 2.加抓取等待时间 每抓取一页都让它随机休息几秒,加入此 ...
- python抓取数据,python使用socks代理抓取数据
在python中,正常的抓取数据直接使用urllib2 这个模块: import urllib2 url = 'http://fanyi.baidu.com/' stream = urllib2.ur ...
- 在mac下使用python抓取数据
2015已经过去,这是2016的第一篇博文! 祝大家新年快乐! 但是我还有好多期末考试! 还没开始复习,唉,一把辛酸泪! 最近看了一遍彦祖的文章叫做 iOS程序员如何使用Python写网路爬虫 所以自 ...
- python抓取数据构建词云
1.词云图 词云图,也叫文字云,是对文本中出现频率较高的"关键词"予以视觉化的展现,词云图过滤掉大量的低频低质的文本信息,使得浏览者只要一眼扫过文本就可领略文本的主旨. 先看几个词 ...
- python 抓取数据,pandas进行数据分析并可视化展示
感觉要总结总结了,希望这次能写个系列文章分享分享心得,和大神们交流交流,提升提升. 因为半桶子水的水平,一直在想写什么,为什么写,怎么写. 直到现在找到了一种好的办法: 1.写什么 自己手上掌握的,工 ...
- python 抓取数据 存入 excel
import requestsimport datetimefrom random import choicefrom time import timefrom openpyxl import loa ...
- Python 抓取数据存储到Mysql中
# -*- coding: utf-8 -*- import os,sys import requests import bs4 import pymysql#import MySQLdb #连接MY ...
- Python 抓取数据存储到Redis中
redis是一个key-value存储结构.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted set ...
- 使用python抓取并分析数据—链家网(requests+BeautifulSoup)(转)
本篇文章是使用python抓取数据的第一篇,使用requests+BeautifulSoup的方法对页面进行抓取和数据提取.通过使用requests库对链家网二手房列表页进行抓取,通过Beautifu ...
随机推荐
- JAVA WEB快速入门之从编写一个JSP WEB网站了解JSP WEB网站的基本结构、调试、部署
接上篇<JAVA WEB快速入门之环境搭建>,在完成了环境搭建后(JDK.Tomcat.IDE),现在是万事具备,就差写代码了,今天就来从编写一个JSP WEB网站了解JSP WEB网站的 ...
- 对HTML5标签的认识(三)
这篇随笔继续来认识HTML标签.这次随笔主要是对<table>标签的认识和最近我学习到的一些标签来和大家分享. 一.<table>标签 <table>标签的作用主要 ...
- 微信web页面返回刷新
问题:在微信web页面开发的过程中,会遇到返回上一个页面数据没有刷新的情况. 解决方案:在该页面监控用户的浏览,每次加载都刷新页面. window.onpageshow = function(even ...
- rocketmq4.x快速入门指南
以下采用的是apache rocketmq 4.2.0版本 相关文档如下 快速体验: http://blog.seoui.com/2018/07/24/rocketmqinstall/ rocketm ...
- XE5 搭建DataSnap服务
1 准备工作 1.1 环境准备 XE5或XE7,操作系统Windows7(64位)操作系统. 数据库MSSQL选择SQLServer2008. 如果数据库服务没有在开发电脑上,则需要在开发电脑上安 ...
- js清空数组的方法
方式1:splice函数 arrayObject.splice(index,howmany,element1,.....,elementX) index:必选,规定从何处添加/删除元素. howman ...
- LeetCode算法题-Longest Word in Dictionary(Java实现)
这是悦乐书的第303次更新,第322篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第171题(顺位题号是720).给出表示英语词典的字符串单词数组,找到单词中长度最长的单 ...
- Java基础系列--02_运算符和程序的语句
运算符: (1)算术运算符: +,-,*,/,%,++,--(加.减.乘.除.取余.自增,自减) ++和--的注意事项: a:他们的作用是自增或者自减 b:使用 1.单独使用 放在操作数据的前面和后面 ...
- socket.io 出现的WebSocket is closed before the connection is established
WebSocket is closed before the connection is established 最近socket.io是挺流行的,幼麟棋牌和一些好的开源项目也使用这个框架,在搭建其平 ...
- maven编译开源项目报enforce错解决
刚下载一个开源项目源码,用maven编译发现报错: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plu ...