当前位置:网站首页>Let's just say I can use thousands of expression packs

Let's just say I can use thousands of expression packs

2022-07-01 03:05:00 Panda aiqia rice

Preface

In today's era when everyone has a mobile phone , Many people chat online , however , How to quickly alleviate embarrassment and enter a happy and pleasant chat ~

A friend I just met threw a few expression packs out and pulled into the relationship every minute , The girlfriend was sulky, and the whole two expressions made her happy , It can also resolve embarrassment , There's no time to type the whole two expression packs , Politeness without embarrassment . I don't know when to go back , It's even more like losing an expression package and solving it in minutes

Now young people chat , I'm embarrassed to say I'm a young man without an expression , Expression pack has become an indispensable part of people's chat .

 Insert picture description here

preparation (https://jq.qq.com/?_wv=1027&k=Ap5XvyNN)

Preparation is important , First know what we're going to do , What to do with , How do you do it? , Go step by step , Slowly but surely .

Development environment configuration

  • Python 3.6
  • Pycharm

If you have a partner who has not installed it, you can get it from the home page on the left or send me a private letter to get the installation tutorial ~

Module installation configuration

  • requests
  • parsel
  • re

Third-party module , We need to install : (https://jq.qq.com/?_wv=1027&k=Ap5XvyNN)

  1. win + R Input cmd Enter the installation command pip install Module name If there is a burst of red Probably because Network connection timeout Switch domestic image source

  2. stay pycharm Click on the Terminal( terminal ) Enter the installation command

How to configure pycharm Inside python Interpreter ?

  1. choice file( file ) >>> setting( Set up ) >>> Project( project ) >>> python interpreter(python Interpreter )

  2. Click on the gear , choice add

  3. add to python The installation path

pycharm How to install plug-ins ?

  1. choice file( file ) >>> setting( Set up ) >>> Plugins( plug-in unit )
  2. Click on Marketplace Enter the name of the plug-in you want to install such as : Translation plug-ins Input translation / Chinese plug-in Input Chinese
  3. Select the corresponding plug-in and click install( install ) that will do
  4. After successful installation Yes, it will pop up restart pycharm The option to Click ok , Restart to take effect

 Insert picture description here

Code

The goal is :fabiaoqing
Please fill in the front and back of the address by yourself , Including the following code , There should be no such thing as that .

The import module

import requests 
import parsel 
python Learning exchange group :660193417 ###
import re
import time

Request URL

url = f'fabiaoqing/biaoqing/lists/page/{page}.html'

Request header

headers = {
       'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'
    }

Return to the web page source code (https://jq.qq.com/?_wv=1027&k=Ap5XvyNN)

response = requests.get(url=url, headers=headers)

get data

#  First extraction   Extract all of div Label content 
divs = selector.css('#container div.tagbqppdiv') # css  Extract the content according to the label 

#  Extract his picture from the tag content url Address 
img_url = div.css('img::attr(data-original)').get()

#  Extract the title 
title = div.css('img::attr(title)').get()

#  Get the suffix of the picture 
name = img_url.split('.')[-1]

Save the data

new_title = change_title(title)

Send a request to the emoticon package picture Get its binary data

img_content = requests.get(url=img_url, headers=headers).content

Save the data

def save(title, img_url, name):

    img_content = get_response(img_url).content
    try:
        with open('img\\' + title + '.' + name, mode='wb') as f:
            #  Write picture binary data 
            f.write(img_content)
            print(' Saving :', title)
    except:
        pass
        
#  Replace special characters in the title python Learning exchange group :660193417 ###
#  Because the file name is unknown and there are special characters , So we need to replace special characters with regular expressions .
def change_title(title):
    new_title = re.sub(mode, "_", title)
    return new_title

Recording time

time_2 = time.time()

use_time = int(time_2) - int(time_1)
print(f' The total time is :{use_time} second ')

Multithreading (https://jq.qq.com/?_wv=1027&k=Ap5XvyNN)

import requests  
import parsel 
import re
import time
import concurrent.futures 



def change_title(title):


    new_title = re.sub(mode, "_", title)
    return new_title


def get_response(html_url):

    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'
    }
    repsonse = requests.get(url=html_url, headers=headers)
    return repsonse


def save(title, img_url, name):

    img_content = get_response(img_url).content
    try:
        with open('img\\' + title + '.' + name, mode='wb') as f:
          
            f.write(img_content)
            print(' Saving :', title)
    except:
        pass


def main(html_url):

    html_data = get_response(html_url).text
    selector = parsel.Selector(html_data) 
    divs = selector.css('#container div.tagbqppdiv') 
    for div in divs:

        img_url = div.css('img::attr(data-original)').get()
 
        title = div.css('img::attr(title)').get()

        name = img_url.split('.')[-1]
 
        new_title = change_title(title)
        save(new_title, img_url, name)


if __name__ == '__main__':
    time_1 = time.time()
    exe = concurrent.futures.ThreadPoolExecutor(max_workers=10)
    for page in range(1, 201):
        url = f'fabiaoqing/biaoqing/lists/page/{page}.html'
        exe.submit(main, url)
    exe.shutdown()
    time_2 = time.time()
    use_time = int(time_2) - int(time_1)
    print(f' The total time is :{use_time} second ')

 Please add a picture description
 Please add a picture description

I'm a panda , See you in the next article (*◡‿◡)

 Insert picture description here

原网站

版权声明
本文为[Panda aiqia rice]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/182/202207010251578296.html