1
我正在制作一个应用程序,用于搜索google关键词并将搜索到的URL附加到列表中。然后将网址发布到twitter。如何随机选取列表中的下一个元素?
我该如何在每小时随机时间从列表中选取一个URL,然后在随后的一个小时内按顺序在列表中选择下一个URL?
import tweepy, time
from google import search
CONSUMER_KEY = 'xxxx'
CONSUMER_SECRET = 'xxxx'
# Create a new Access Token
ACCESS_TOKEN = 'xxxx'
ACCESS_SECRET = 'xxxx'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
api = tweepy.API(auth)
#search google for url key links
lst = [] #list holding URL
for url in search('python', stop=20):
lst.append(url)
print(url)
lst = [ x for x in lst if "wiki" not in x ]
# What the bot will tweet
for line in lst:
api.update_status(line)
print line
print '...'
time.sleep(1)
print "All done!"
在此先感谢您。
到底在坚持什么? – glibdud
@glibdud我被困住了,如何从每小时/每小时随机时间的列表中选取一个元素 – RustyShackleford
尽管如此,还是有很多步骤。你需要知道如何生成['random'](https://docs.python.org/3.6/library/random.html)数字吗?你只是在寻找['sched'](https://docs.python.org/3.6/library/sched.html)模块? – glibdud