python爬虫之抓取500彩票网大乐透走势图

import requests
from bs4 import BeautifulSoup
import json
results = []
 
def find_tops(url):
 
 
	wb_data = requests.get(url)
	wb_data.encoding = 'utf-8'
 
	soup = BeautifulSoup(wb_data.text, "html.parser")
 
	alls = soup.select("#chartsTable tr")
 
	issues = alls[2:-15]
	tongjis = alls[-6:-2]
	
	for each in tongjis:
		data = {'title':'','content':[]}
		tds = each.select('td')
		for td in tds:
			if td.get('align') != None:
				data['title'] = td.get_text().strip()
			else:
				td_number = td.get_text().strip()
				data['content'].append({'color':'','number':td_number})
		results.append(data)
 
 
	for each in issues:
		data = {'title':'','content':[]}
		tds = each.select('td')
		for td in tds:
			if td.get('colspan') != None:
				continue
			if td.get('align') != None:
				data['title'] = td.get_text().strip()
				# print(data['title'])
			else:
				# print(td.get('colspan'))
				# print(td.get('class'))
				td_class = td.get('class')[0]
				td_number = td.get_text().strip()
				td_color = ''
				if td_class == "yl01":
					td_color = 'gray1'
				elif  td_class == 'yl02':
					td_color = 'gray2'
				elif  td_class == 'chartBall01':
					td_color = 'red'
				elif td_class == 'chartBall02':
					td_color = 'blue'
				
				data['content'].append({'color':td_color,'number':td_number})
		results.append(data)
 
		
	
 
url = 'http://datachart.500.com/dlt/zoushi/newinc/jbzs_foreback.php?expect=50'
 
find_tops(url)
print(json.dumps(results))

 

至此已经拿到大乐透50期内走势图,可以将数据入库等供自己系统使用

有一起做彩票项目的,可以联系QQ 532063419,大家一起交流更好的开发系统

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值