使用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 ...
随机推荐
- chrome 错误 ERR_CACHE_READ_FAILURE
问题现象 谷歌浏览器,点击后退按键提示:ERR_CACHE_READ_FAILURE 错误 解决办法 1. chrome://flags/#enable-simple-cache-backend 2. ...
- MySQL via EF6 的试用报告
1.如何通过 EF6 来连接 MySQL? 2.如何通过 EF6 来实现 CRUD? 2.1.Create 添加 2.2.Retrieve 查询 2.3.Update 修改 2.4.Delete 删除 ...
- Java设计模式系列-装饰器模式
原创文章,转载请标注出处:<Java设计模式系列-装饰器模式> 一.概述 装饰器模式作用是针对目标方法进行增强,提供新的功能或者额外的功能. 不同于适配器模式和桥接模式,装饰器模式涉及的是 ...
- C# 添加枚举中文资源
在业务开发过程中,添加枚举,在固定枚举值的同时,也需要中文的文案. 如果不想添加语言资源项.添加枚举转语资源项,可以使用特性标记. 属性描述 DescriptionAttribute 先看案例: pu ...
- acrobat pdf 按页拆分
百度 https://jingyan.baidu.com/article/37bce2be7098a21002f3a2f2.html 百度acrobat版本比我的高,操作不同了: 我的方案: 组织页面 ...
- SpringBoot2 application.properties方式加载配置文件
application.properties jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://127.0.0.1:33 ...
- win10安装tensorflow-gpu1.13.1+cuda10.0+cudnn7.3.1
一,本机配置 Win10 64bit NVIDIA GeForce GTX 960M Python3.7(Anaconda) 二,安装CUDA 亲测,TensorFlow-gpu1.13.1支持cud ...
- 2016年第七届蓝桥杯javaB组 试题 答案 解析
1.煤球数目 有一堆煤球,堆成三角棱锥形.具体: 第一层放1个, 第二层3个(排列成三角形), 第三层6个(排列成三角形), 第四层10个(排列成三角形), .... 如果一共有100层,共有多少个煤 ...
- 总结安装webpack过程中遇到的错误及解决方案
1.安装不成功的报错: 解决方案:清除缓存 2.打包不成功: 解决方案:填写打包路径时的“__dirname”有两个下划线 3.打包报错: 解决方案:正确填写路径为“./style.css”
- SSH实现登陆拦截器
/** * 登录验证拦截器 * */ @SuppressWarnings("serial") public class LoginInteceptor implements Int ...