Îá°®Æƽâ - 52pojie.cn

 ÕÒ»ØÃÜÂë
 ×¢²á[Register]

QQ怬

Ö»ÐèÒ»²½£¬¿ìËÙ¿ªÊ¼

²é¿´: 1212|»Ø¸´: 2
ÊÕÆð×ó²à

[ÌÖÂÛ] pythonͼƬץȡԴÂë

[¸´ÖÆÁ´½Ó]
ʯäÁÔª ·¢±íÓÚ 2020-8-31 11:58
import requests
from lxml import etree


# ¶¨Òåαװͷ£¬ÅûÉÏÂí¼×¼Ù×°×Ô¼ºÊÇä¯ÀÀÆ÷
header = {
    # refererÊÇÓÃÀ´»ñÈ¡HTTPµÄÀ´Ô´µØÖ·£¬¼òµ¥Ëµ¾ÍÊÇrefererÐÅÏ¢»á¸æËß·þÎñÆ÷Ë­·¢ÆðµÄÇëÇó¡£
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
    "referer": "http://www.huitu.com/topic-detail/3857.html?recType=0"
}

# 1¡¢ÇëÇóÃÃ×ÓͼÄõ½ÍøÕ¾ÕûÌåÊý¾Ý
response = requests.get("http://www.huitu.com/topic-detail/3857.html?recType=0", headers=header)

# 2¡¢Êý¾Ý½âÎöÔ¤´¦Àí
html = etree.HTML(response.text)

# 3¡¢»ñÈ¡±êÌâÃû×Ö
alt_list = html.xpath('//img[@class="lazy"]/@alt')
# print(src_list)

# 4¡¢»ñÈ¡ÏÂÔØÁ´½Ó
src_list = html.xpath('//img[@class="lazy"]/@data-original')
# print(src_list)

# ±éÀúÁ½¸öÁбí,ÐèÒªÌáÇ°½¨Á¢photoÎļþ¼Ð
for alt, src in zip(alt_list, src_list):
    # 5¡¢Í¨¹ýÏÂÔØÁ´½ÓÇëÇóͼƬÊý¾Ý
    image = requests.get(url=src, headers=header)

    # 6¡¢±£´æͼƬ
    file_name = "./photo/" + alt + ".jpg"
    print("ÕýÔÚ±£´æͼƬÎļþ£º" + file_name)
    with open(file_name, "wb") as file:
        file.write(image.content)
ÒÔÉÏ´úÂë½ö¹©Ñ§Ï°Ê¹ÓÃ,ϲ»¶µÄÇ×ÃǶà¶àµãÔÞ¹ÄÀøÏÂÀϵܣ¬ÎÒÊÇÐÂÈË¡£

Ãâ·ÑÆÀ·Ö

²ÎÓëÈËÊý 2Îá°®±Ò +2 ÈÈÐÄÖµ +1 ÊÕÆð ÀíÓÉ
the_stars + 1 + 1 ÕûÌå¿´×źܹ淶
BlovedCQ + 1 ΪÏêϸ´ò·Ö

²é¿´È«²¿ÆÀ·Ö

·¢ÌûÇ°ÒªÉÆÓá¾ÂÛ̳ËÑË÷¡¿¹¦ÄÜ£¬ÄÇÀï¿ÉÄÜ»áÓÐÄãÒªÕҵĴ𰸻òÕßÒѾ­ÓÐÈË·¢²¼¹ýÏàͬÄÚÈÝÁË£¬ÇëÎðÖظ´·¢Ìû¡£

C¸ç888 ·¢±íÓÚ 2020-8-31 14:15
×¢ÊͺÜÏêϸ£¬²»´í
 Â¥Ö÷| ʯäÁÔª ·¢±íÓÚ 2020-9-1 09:45
ÄúÐèÒªµÇ¼ºó²Å¿ÉÒÔ»ØÌû µÇ¼ | ×¢²á[Register]

±¾°æ»ý·Ö¹æÔò

·µ»ØÁбí

RSS¶©ÔÄ|СºÚÎÝ|´¦·£¼Ç¼|ÁªÏµÎÒÃÇ|Îá°®Æƽâ - LCG - LSG ( ¾©ICP±¸16042023ºÅ | ¾©¹«Íø°²±¸ 11010502030087ºÅ )

GMT+8, 2024-11-26 13:58

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

¿ìËٻظ´ ·µ»Ø¶¥²¿ ·µ»ØÁбí