异步协程 的 trip库

 

import trip
headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.89 Safari/537.36',
    'Referer':'https://ad.weibo.com/ad/index/manage?customer_id=3065727027',
    'Cookie':'''XXX'''}

s = trip.Session()

links = []
with open('uids','r') as f:
    for i in f:
        link= 'https://ad.weibo.com/aj/widget/indexLeftBar?customer_id={}'.format(i.strip())
        links.append(link)

@trip.coroutine
def fetch():
    res = yield [s.get(link,headers=headers) for link in links]
    for r in res:
        uid = r.url.split('=')[1]
        plans = r.json()['result']['adDelivering']
        print(uid,plans)

trip.run(fetch)

 

 

posted @ 2017-11-10 11:52  Erick-LONG  阅读(222)  评论(0编辑  收藏  举报