spoof python script - automatically create a folder crawling pictures

Original link: https://blog.csdn.net/fangye945a/article/details/102492943

Python spoof script - Create a folder crawling pictures

Preamble
read some reptiles on the blog, drawing on their knowledge of reptiles, packing about crawlers spoof about a friend

Implementation
1. In the 64-bit environment python
2. Packing code

code show as below

import os, sys
import requests
from lxml import etree
def pachong():
    loop = 1 #定义循环次数,可要可不要
    path = 'C:\\'#创建文件路径
    

    cur = 0
    while cur<loop: #创建文件个数

            file_name = path + "看图片"
            try:
                os.mkdir(file_name)
            except FileExistsError:
                pass

            #爬取图片
            for i in range(446):
                url = "https://www.mzitu.com/zipai/comment-page-{}/".format(i);
                print(url)
                heads = {"user-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"}
                heads.update(referer=url)
                response = requests.get(url + "#comments", headers = heads)
                html = etree.HTML(response.text)
            #   alt_list = html.xpath('//img[@class="lazy"]/@alt')
                src_list = html.xpath('//img[@class="lazy"]/@data-original')
                j = 0
                for src in src_list:
                    j = j + 1
                    content = requests.get(src, headers=heads).content
                    filename = file_name+"\\{}_{}.jpg".format(i,j)
                    print("正在保存图片文件:{}".format(filename))
                    with open(filename, "wb") as f:
                        f.write(content)

            #爬取结束

        i=i+1
mkdir()

Program Description

  • The program can automatically create a folder on the C drive and reptiles, will climb into the picture file is automatically created folder inside. For simple, quick access to pictures sister, here crawlers imported bloggers following reptiles. Have to praise the crawler is very well written https://blog.csdn.net/fangye945a/article/details/102492943

File packaging

The script can only be used on computers python in their own environment, in order to be able to run on a computer does not install python environment can be used to package pyinstaller generate the .exe file.

Packaging operations

1. dos interface installation pyinstaller, install a small partner may be omitted

pip install pyinstaller

2. Then in the dos interface, folder entry code input line of code will automatically generate an .exe file. Run the file.

pyinstaller -F -w ***.py

After executing the file results
Here Insert Picture Description in the dist directory will have a .exe file that can be run directly.

Run the code generator results

1. Run the finished code, C inside the disk will automatically generate a folder, which will have the picture you want.
2. according to the actual situation, the code will increase the number of cycles will generate numerous file
folder. The .exe to a friend, you can be friends spoof, provided that the computer must be 64-bit.
3. If they do not accidentally run the code, you can immediately delete the folder to save your life.

Guess you like

Origin blog.csdn.net/weixin_44427658/article/details/102749626