Directorio de artículos
1. Preparación
módulos utilizados
requests
threading
Objetivo
360图片
Cree un archivo llamado img y guarde la imagen.
En segundo lugar, el efecto
Imparable
3. Código
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()
También preparé estos materiales para usted, simplemente escanéelos a continuación.
Resumen de la ruta de aprendizaje de
Python Excelentes libros de aprendizaje de Python Colección de 100
videos introductorios de
Python Caso práctico de
Python Preguntas de la entrevista
de Python Herramientas de software relacionadas con Python
¡Hermanos, vayan!