コード例 #1
0
 def get_image(chpath, imageurls):
     print(chpath)
     head = {
         'User-Agent':
         'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36'
     }
     reqs = [ahttp.get(url, headers=head) for url in imageurls]
     reps = ahttp.run(reqs)
     for i, rep in enumerate(reps):
         filepath = r'%s\%s\%s.jpg' % (settings.IMAGES_STORE, chpath, i)
         print(rep)
         with open(filepath, 'wb') as writer:
             writer.write(rep.content)
コード例 #2
0
ファイル: grequests集.py プロジェクト: jiqi136/BTT6
def ahttp随机无序集():#grequests.map(任务列


    会话 = ahttp.Session(headers = 头部信息)

    页数网址 = 'http://91btbtt.com/forum-index-fid-951-page-123.htm'#http://www.mzitu.com/page/3/
    任务列表=[]
    for 倒页数 in range(15,5,-1):
        各帖子链接 = str(页数网址).replace("123", str(倒页数))
        任务=会话.get(各帖子链接,pool=1,timeout=len(任务列表)//2,size=2)
        任务列表.append(任务)


    条件循环 = 1
    次数循环 = 0
    print('len(任务列表)//2',len(任务列表)//2)  # 异常
    while 条件循环 == 1:
        try:  # 调用异常处理,应对易发生错误的位置
            返回网页内容集 = ahttp.run(任务列表)  # size=3 并发数 3  gtimeout超时时间


        except:  # (re) as 异常
            print('网络异常等待')# 异常
            print('倒数9秒再连接', 次数循环, '次')
            # time.sleep(3)

        else:
            返回网页内容集文本=str(返回网页内容集)
            if '200' in 返回网页内容集文本 and 'None'not in 返回网页内容集文本 and  '40' not in 返回网页内容集文本:

                print('返回网页内容集', 返回网页内容集)
                条件循环 = 0
                #return  # 返回
            else:
                print('网站网络异常,状态码:',返回网页内容集)
                time.sleep(1)

    for 返回网页内容 in 返回网页内容集:
        print('返回网页内容url',返回网页内容.url)
        返回网页内容.encoding = "UTF-8"


    print('完成')
コード例 #3
0
    def ahttp随机无序集(self):  # grequests.map(任务列

        会话 = ahttp.Session(headers=头部信息)

        页数网址 = 'http://www.iyi8.com/photo/mm/{}.html'  # http://www.mzitu.com/page/3/
        任务列表 = []
        for 倒页数 in range(15, 5, -1):
            各帖子链接 = 页数网址.format(
                str(倒页数)
            )  #不换行 end=""  request("GET"  pool=1, ,size=2 pool=1,timeout=len(任务列表)//2,
            print('各帖子链接', 各帖子链接)
            任务 = ahttp.get(各帖子链接, size=1, headers=头部信息)
            任务列表.append(任务)

        条件循环 = 1
        次数循环 = 0
        print('len(任务列表)//2', len(任务列表) // 2)  # 异常
        while 条件循环 == 1:
            try:  # 调用异常处理,应对易发生错误的位置
                返回网页内容集 = ahttp.run(任务列表)  # size=3 并发数 3  gtimeout超时时间

            except:  # (re) as 异常
                print('网络异常等待')  # 异常
                print('倒数9秒再连接', 次数循环, '次')
                # time.sleep(3)

            else:
                返回网页内容集文本 = str(返回网页内容集)
                if '200' in 返回网页内容集文本 and 'None' not in 返回网页内容集文本 and '40' not in 返回网页内容集文本:
                    print('返回网页内容集', 返回网页内容集)
                    条件循环 = 0
                    # return  # 返回
                else:
                    print('网站网络异常,状态码:', 返回网页内容集)
                    time.sleep(1)

        for 返回网页内容 in 返回网页内容集:
            print('返回网页内容url', 返回网页内容.url)
            返回网页内容.encoding = "UTF-8"
        print('完成')
コード例 #4
0
ファイル: test.py プロジェクト: HPM-DCM/Scrapy_borenzhuan
import ahttp
image_url = [
    'https://img001.bolong-aterials.com/images/comic/393/784347/118a3133d9.jpg/0',
    'https://img001.bolong-aterials.com/images/comic/393/784347/1111455a1d.jpg/0',
    'https://img001.bolong-aterials.com/images/comic/393/784347/110fc320d0.jpg/0'
]
head = {
    'User-Agent':
    'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36'
}
reqs = [ahttp.get(url, headers=head) for url in image_url]
responses = ahttp.run(reqs)
for i, resp in enumerate(responses):
    file = '%s.jpg' % i
    print(resp)
    with open(file, 'wb') as writer:
        writer.write(resp.content)
コード例 #5
0
ファイル: aokhttpTest.py プロジェクト: mygoodname/pythonTest
import ahttp

urls = [f"https://movie.douban.com/top250?start={i*25}" for i in range(10)]
reqs = [ahttp.get(url) for url in urls]
resps = ahttp.run(reqs)
print(resps)
print(resps[0].text)