程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python:** thats all. I collected it~

編輯:Python

Preface

Hi. ! Hello, everyone , This is the little panda

Knowledge point :

  • The basic flow
  • fiddler Grab the bag

development environment :

  • python 3.8 Run code
  • pycharm 2021.2 Auxiliary knock code
  • requests Third-party module

If installed python Third-party module :

  • win + R Input cmd Click ok , Enter the installation command pip install Module name (pip install requests) enter
  • 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

Code

 Welcome to white whoring Q Group :660193417###
import requests
import re
import json
import os
headers = {
'Host': 'mp.weixin.qq.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x63060012)',
'Cookie': 'wxuin=2408215323; lang=zh_CN; pass_ticket=TsrY5cXMvTN01ghVFxFxT9k4jdPONJBt8mdl0ta20qxjUHNsnkkWLjib4gXCXSQM; devicetype=android-29; version=2800153f; wap_sid2=CJvmqfwIEooBeV9IQVVCUVAzdVBlWEo5NTlySFpON1Ffek5zTE9qRi1jdWZjVFMyOFYyM0FyVE9RSTRNZ3VuUXFTcU94Q3lKY1VyQlJ2RkEtTWFyRWFLeHhJUTRrWmp0N0VDZ05zOFV4d0kzZ1p5cXBIbTVBbEZGRWJteEt4Q0oxSjY4ZHFhODlaZnMyY1NBQUF+MOXS6ZIGOA1AlU4=',
}
for page in range(0, 3):
url = f'https://mp.weixin.qq.com/mp/profile_ext?action=getmsg&__biz=MzU0MzU4OTY2NQ==&f=json&offset={page * 10}&count=10&is_ok=1&scene=&uin=777&key=777&pass_ticket=&wxtoken=&appmsg_token=1161_7%252BO7mVaQbImKSRrYWqKBnNggweX4WNZaqjadeg~~&x5=0&f=json'
json_data = requests.get(url=url, headers=headers).json()
general_msg_list = json_data['general_msg_list']
general_msg_list = json.loads(general_msg_list)['list']
# print(general_msg_list)
title_list = []
content_url_list = []
for general_msg in general_msg_list:
title = general_msg['app_msg_ext_info']['title']
content_url = general_msg['app_msg_ext_info']['content_url']
multi_app_msg_item_list = general_msg['app_msg_ext_info']['multi_app_msg_item_list']
title_list.append(title)
content_url_list.append(content_url)
for multi_app_msg_item in multi_app_msg_item_list:
title_list.append(multi_app_msg_item['title'])
content_url_list.append(multi_app_msg_item['content_url'])
# print(title_list)
# print(content_url_list)
zip_data = zip(title_list, content_url_list)
for detail_title, detail_url in zip_data:
if not os.path.exists('img/' + detail_title):
os.mkdir('img/' + detail_title)

1. Send a request

 Welcome to white whoring Q Group :660193417###
response = requests.get(url=detail_url, headers=headers)

2. get data

 html_data = response.text

3. Parsing data

 Welcome to white whoring Q Group :660193417###
# Regular match data The first parameter Need matching rules
# The first parameter In which string does it match
img_list = re.findall('data-src="(https://mmbiz\.qpic\.cn/.*?)"', html_data)
print(detail_title)
# print(img_list)
for img in img_list:
if not 'gif' in img:
img_data = requests.get(img).content
img_name = img.split('/')[-2]
print(img_name)
with open(f'img/{detail_title}/{img_name}.jpeg', mode='wb') as f:
f.write(img_data)

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


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved