找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 1841|回复: 2

[求助] 业余0基础的求助

1

主题

2

帖子

2

积分

贫民

积分
2
hyifan 发表于 2018-5-3 14:56:12 | 显示全部楼层 |阅读模式
本帖最后由 hyifan 于 2018-5-3 17:03 编辑

小弟没有编程基础,花了好几个小时写了下面这个烂程序,想通过它方便一下自己的工作,现有两个问题想求助一下大神.
1. 怎样才能让程序不断循环访问url来获取最新的数据?
2. 如果我有20个url,怎样才能让程序循环访问这些url?


import urllib2
import json
  
html = urllib2.urlopen(r'http://www.aaa.com')


hjson = json.loads(html.read())

time0 = int (hjson['Record'][0]['Time'][0]['Count'])
time1 = int (hjson['Record'][0]['Time'][1]['Count'])
time2 = int (hjson['Record'][0]['Time'][2]['Count'])
time3 = int (hjson['Record'][0]['Time'][3]['Count'])
time4 = int (hjson['Record'][0]['Time'][4]['Count'])
time5 = int (hjson['Record'][0]['Time'][5]['Count'])

if time0 < 1:
        print hjson['Record'][0]['Date'],
        print "time0",
        print time0,
        print "Yes!"

if time1 < 1:
        print hjson['Record'][0]['Date'],
        print "time1",
        print time1,        
        print "Yes!"

if time2 < 1:
        print hjson['Record'][0]['Date'],
        print "time2",
        print time2,
        print "Yes!"

if time3 < 1:
        print hjson['Record'][0]['Date'],
        print "time3",
        print time3,
        print "Yes!"

if time4 < 1:
        print hjson['Record'][0]['Date'],
        print "time4",
        print time4,
        print "Yes!"

if time5 < 1:
        print hjson['Record'][0]['Date'],
        print "time5",
        print time5,
        print "Yes!"
else:
        print "Bye"
回复

使用道具 举报

0

主题

956

帖子

956

积分

圣骑士

积分
956
sheeboard 发表于 2018-5-3 19:53:15 | 显示全部楼层
放到while True: 里就可以一直循环,或是写crontab定时运行,20个地址放到list里for url in listname就可以循环访问了。不过最好先弄本有关爬虫的书看看,稍微学习一下。
回复 支持 反对

使用道具 举报

1

主题

2

帖子

2

积分

贫民

积分
2
hyifan  楼主| 发表于 2018-5-3 22:58:35 | 显示全部楼层
sheeboard 发表于 2018-5-3 19:53
放到while True: 里就可以一直循环,或是写crontab定时运行,20个地址放到list里for url in listname就可以 ...

虽然看不大懂,但还是感谢,我再琢磨琢磨..
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表