1.準備
使用したモジュール
requests
threading
目標
360图片
imgという名前のファイルを作成し、画像を保存します。
第二に、効果
止められない
3.コード
import requests
import threading
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'
}
def get_response(html_url):
response = requests.get(url=html_url, headers=headers)
return response
def save(img_url, title):
path = 'img\\' + title + '.jpg'
img_content = get_response(img_url).content
with open(path, mode='wb') as f:
f.write(img_content)
print('正在保存:', title)
def main(url):
html_data = get_response(url).json()
lis = html_data['list']
for li in lis:
img_url = li['qhimg_downurl']
title = li['title']
save(img_url, title)
if __name__ == '__main__':
for page in range(0, 301, 30):
url = 'https://image.so.com/zjl?ch=beauty&sn={}&listtype=new&temp=1'.format(page)
main_thread = threading.Thread(target=main, args=(url,))
main_thread.start()
これらの資料も用意しました。以下をスキャンしてください。
Python学習ルートの概要
優れたPython学習ブック
100Python入門ビデオコレクション
Pythonの実用的なケース
Pythonインタビューの質問
Python関連のソフトウェアツール
兄弟よ、行け!