美文网首页
Socket爬虫图片打开提示不支持此格式

Socket爬虫图片打开提示不支持此格式

作者: 木有枝兮 | 来源:发表于2019-12-08 13:58 被阅读0次

    环境:python3.7.2

    尝试用Socket爬虫网站:http://desk.zol.com.cn/

    附代码:

    #https://desk-fd.zol-img.com.cn/t_s960x600c5/g5/M00/00/07/ChMkJl3qNKaIDNA2AARqqK0FxbEAAvnJAJbLQMABGrA592.jpg

    import socket

    b=socket.socket()

    b.connect(('desk-fd.zol-img.com.cn',80))

    req_line='GET /t_s960x600c5/g5/M00/00/07/ChMkJl3qNKaIDNA2AARqqK0FxbEAAvnJAJbLQMABGrA592.jpg HTTP/1.1\r\n'

    req_header='host:desk-fd.zol-img.com.cn\r\nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36\r\nReferer: http://desk.zol.com.cn/bizhi/8376_103845_2.html\r\n'

    empty_line='\r\n'

    req_content=''

    b.send((req_line+req_header+empty_line+req_content).encode())

    complete_content=b''

    res_content=b.recv(4096)

    while res_content:

        complete_content+=res_content

    res_content=b.recv(4096)

    print(len(res_content))

    with open('d:/temp2.jpg','wb')as f:

        f.write(complete_content)

    执行结果:正常

    问题:图片和网上下载的大小一样,打开提示不支持此格式

    用网页下载的图一正常打开

    相关文章

      网友评论

          本文标题:Socket爬虫图片打开提示不支持此格式

          本文链接:https://www.haomeiwen.com/subject/hflucqtx.html