Regular crawling Jingdong commodity information and packaged into .exe executable program.

--- --- restore content begins

 This article crawling content, enter a keyword to search automatically crawling Jingdong site-related merchandise store name, product name, price, crawling 100 (Total 100)

code show as below;

import requests
import re
# 请求头
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'
}

def get_all(url,key):
    for page in range(1,200,2):
        params = {
            'keyword':key,
            'enc':'utf-8',
            'page':page
        }
        num = int((int(page)+1)/2)
        try:
            response = requests.get(url=url,params=params,headers=headers)
            # 转码
            content = response.text.encode(response.encoding).decode(response.apparent_encoding)
            data_all = re.findall('<div class="p-price">.*?<i>(.*?)</i>.*?<div class="p-name p-name-type-2">.*?title="(.*?)"'
                                  '.*?<div class="p-shop".*?title="(.*?)"',content,re.S)
            for i in data_all:
                with open(key + ' .Txt ' , ' A + ' , encoding = ' UTF-. 8 ' ) AS F: 
                    f.write ( ' Store Name: ' + I [2] + ' \ n- ' + ' Product Name: ' + I [. 1 ] + ' \ n- ' + ' Rates: ' + I [0] + ' \ n-\ n- ' )
                 Print ( ' first ' + STR (NUM) + ' p ' + ' data download ....')
         The except Exception AS E:
             Print (E) 


IF  __name__ == ' __main__ ' :
     Print ( ' content you want to search, Jingdong Mall get inside the product name, store name, commodity price ' ) 
    Key = the INPUT ( ' type a search : ' ) 
    url = ' https://search.jd.com/Search? ' 
    get_all (url, Key)

Packaged into an executable .exe file.

You need to use pyinstaller package pip download;

pip install pyinstaller

Create online a .ico icon for the program when the picture, the program icon and placed in the same folder,

 

 

Open a command line window in the .py file directory, execute packaging commands;

E: \ exercises \ final stage \ 0808 \ JD1> pyinstaller -F -i 01.ico jd.py

 

 

--- end --- restore content

 This article crawling content, enter a keyword to search automatically crawling Jingdong site-related merchandise store name, product name, price, crawling 100 (Total 100)

code show as below;

import requests
import re
# 请求头
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'
}

def get_all(url,key):
    for page in range(1,200,2):
        params = {
            'keyword':key,
            'enc':'utf-8',
            'page':page
        }
        num = int((int(page)+1)/2)
        try:
            response = requests.get(url=url,params=params,headers=headers)
            # 转码
            content = response.text.encode(response.encoding).decode(response.apparent_encoding)
            data_all = re.findall('<div class="p-price">.*?<i>(.*?)</i>.*?<div class="p-name p-name-type-2">.*?title="(.*?)"'
                                  '.*?<div class="p-shop".*?title="(.*?)"',content,re.S)
            for i in data_all:
                with open(key + ' .Txt ' , ' A + ' , encoding = ' UTF-. 8 ' ) AS F: 
                    f.write ( ' Store Name: ' + I [2] + ' \ n- ' + ' Product Name: ' + I [. 1 ] + ' \ n- ' + ' Rates: ' + I [0] + ' \ n-\ n- ' )
                 Print ( ' first ' + STR (NUM) + ' p ' + ' data download ....')
         The except Exception AS E:
             Print (E) 


IF  __name__ == ' __main__ ' :
     Print ( ' content you want to search, Jingdong Mall get inside the product name, store name, commodity price ' ) 
    Key = the INPUT ( ' type a search : ' ) 
    url = ' https://search.jd.com/Search? ' 
    get_all (url, Key)

Packaged into an executable .exe file.

You need to use pyinstaller package pip download;

pip install pyinstaller

Create online a .ico icon for the program when the picture, the program icon and placed in the same folder,

 

 

 

 

Open a command line window in the .py file directory, execute packaging commands;

E: \ exercises \ final stage \ 0808 \ jd1> pyinstaller -F -i dog.ico jd.py

Appeared successfully representing packed success;

27525 INFO: Building EXE from EXE-00.toc completed successfully.

dist executable files in the current folder in the folder;

running result;

You can execute multiple programs;

Output;

done。

 

Guess you like

Origin www.cnblogs.com/nmsghgnv/p/11324959.html
Recommended