def main(): words = ['贸易战'] baidu_url = 'https://www.baidu.com/s?wd=%s' urls = [baidu_url % (word) for word in words] # make data flow net insert = Insert( "insert into test.baidu (id,name ,url,page_rank,page_no)values('{id}','{name}' ,'{url}',{page_rank},{page_no})", **dbconf) p = Pipe( urls, HttpLoader(), Branch(get_all_items, join=True), Branch(get_all_page_url, HttpLoader(), get_all_items, share=False, join=True, route_type=HttpResponse), insert, ) Pipe(Timer(delay=2, until=p.finished), show_info) Bot.render('ex_output/baiduspider') Bot.run()
def main(): Pipe( Timer(delay=2, max_time=5), "http://api.coindesk.com/v1/bpi/currentprice.json", HttpLoader(), lambda r: r.json['bpi']['USD']['rate_float'], print, ) Bot.render('ex_output/simple_bitcoin_price') Bot.run()
def main(): words = ['贸易战', '世界杯'] baidu_url = 'https://www.baidu.com/s?wd=%s' urls = [baidu_url % (word) for word in words] outputfile = aiofile('ex_output/baidu.txt') Pipe( urls, HttpLoader(), Branch(get_all_items, outputfile), Branch(get_all_page_url, HttpLoader(), get_all_items, outputfile), ) #生成流程图 Bot.render('ex_output/baiduspider') Bot.run()