首页 > 其他分享 >cookies加密__搜狗微信

cookies加密__搜狗微信

时间:2022-09-01 15:14:34浏览次数:62  
标签:__ 搜狗 cookies zh para url re params uigs

# coding=utf-8

import requests
from lxml import etree
import re
import random
import json
from urllib import parse


def get_cookie(response1, uigs_para, UserAgent):
SetCookie = response1.headers['Set-Cookie']
cookie_params = {
"ABTEST": re.findall('ABTEST=(.*?);', SetCookie, re.S)[0],
"SNUID": re.findall('SNUID=(.*?);', SetCookie, re.S)[0],
"IPLOC": re.findall('IPLOC=(.*?);', SetCookie, re.S)[0],
"SUID": re.findall('SUID=(.*?);', SetCookie, re.S)[0]
}

url = "https://www.sogou.com/sug/css/m3.min.v.7.css"
headers = {
"Accept": "text/css,*/*;q=0.1",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
"Connection": "keep-alive",
"Cookie": "SNUID={}; IPLOC={}".format(cookie_params['SNUID'], cookie_params['IPLOC']),
"Host": "www.sogou.com",
"Referer": "https://weixin.sogou.com/",
"User-Agent": UserAgent
}
response2 = requests.get(url, headers=headers)
SetCookie = response2.headers['Set-Cookie']
cookie_params['SUID'] = re.findall('SUID=(.*?);', SetCookie, re.S)[0]

url = "https://weixin.sogou.com/websearch/wexinurlenc_sogou_profile.jsp"
headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
"Connection": "keep-alive",
"Cookie": "ABTEST={}; SNUID={}; IPLOC={}; SUID={}".format(cookie_params['ABTEST'], cookie_params['SNUID'], cookie_params['IPLOC'],
cookie_params['SUID']),
"Host": "weixin.sogou.com",
"Referer": response1.url,
"User-Agent": UserAgent
}
response3 = requests.get(url, headers=headers)
SetCookie = response3.headers['Set-Cookie']
cookie_params['JSESSIONID'] = re.findall('JSESSIONID=(.*?);', SetCookie, re.S)[0]

url = "https://pb.sogou.com/pv.gif"
headers = {
"Accept": "image/webp,*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
"Connection": "keep-alive",
"Cookie": "SNUID={}; IPLOC={}; SUID={}".format(cookie_params['SNUID'], cookie_params['IPLOC'], cookie_params['SUID']),
"Host": "pb.sogou.com",
"Referer": "https://weixin.sogou.com/",
"User-Agent": UserAgent
}
response4 = requests.get(url, headers=headers, params=uigs_para)
SetCookie = response4.headers['Set-Cookie']
cookie_params['SUV'] = re.findall('SUV=(.*?);', SetCookie, re.S)[0]

return cookie_params


def get_k_h(url):
b = int(random.random() * 100) + 1
a = url.find("url=")
url = url + "&k=" + str(b) + "&h=" + url[a + 4 + 21 + b: a + 4 + 21 + b + 1]
return url


def get_uigs_para(response):
uigs_para = re.findall('var uigs_para = (.*?);', response.text, re.S)[0]
if 'passportUserId ? "1" : "0"' in uigs_para:
uigs_para = uigs_para.replace('passportUserId ? "1" : "0"', '0')
uigs_para = json.loads(uigs_para)
exp_id = re.findall('uigs_para.exp_id = "(.*?)";', response.text, re.S)[0]
uigs_para['right'] = 'right0_0'
uigs_para['exp_id'] = exp_id[:-1]
return uigs_para


def main_v4(list_url, UserAgent):
headers1 = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
"Connection": "keep-alive",
"Host": "weixin.sogou.com",
"Upgrade-Insecure-Requests": "1",
"User-Agent": UserAgent,
}
response1 = requests.get(list_url, headers=headers1)
html = etree.HTML(response1.text)
urls = ['https://weixin.sogou.com' + i for i in html.xpath('//div[@class="img-box"]/a/@href')]

uigs_para = get_uigs_para(response1)
params = get_cookie(response1, uigs_para, UserAgent)
approve_url = 'https://weixin.sogou.com/approve?uuid={}'.format(uigs_para['uuid'])
headers2 = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
"Connection": "keep-alive",
"Cookie": "ABTEST={}; IPLOC={}; SUID={}; SUV={}; SNUID={}; JSESSIONID={};".format(params['ABTEST'], params['IPLOC'],
params['SUID'], params['SUV'], params['SNUID'],
params['JSESSIONID']),
"Host": "weixin.sogou.com",
"Referer": response1.url,
"User-Agent": UserAgent,
"X-Requested-With": "XMLHttpRequest"
}
for url in urls:
response2 = requests.get(approve_url, headers=headers2)
url = get_k_h(url)
headers3 = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
"Connection": "keep-alive",
"Cookie": "ABTEST={}; SNUID={}; IPLOC={}; SUID={}; JSESSIONID={}; SUV={}".format(params['ABTEST'], params['SNUID'],
params['IPLOC'], params['SUID'],
params['JSESSIONID'],
params['SUV']),
"Host": "weixin.sogou.com",
"Referer": list_url,
"Upgrade-Insecure-Requests": "1",
"User-Agent": UserAgent
}
response3 = requests.get(url, headers=headers3)

fragments = re.findall("url \+= '(.*?)'", response3.text, re.S)
itemurl = ''
for i in fragments:
itemurl += i

# 文章url拿正文
headers4 = {
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
"accept-encoding": "gzip, deflate, br",
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
"cache-control": "max-age=0",
"user-agent": UserAgent
}
response4 = requests.get(itemurl, headers=headers4)
html = etree.HTML(response4.text)
print(response4.status_code)
print(html.xpath('//meta[@property="og:title"]/@content')[0])


if __name__ == "__main__":
key = "我无敌"
url = 'https://weixin.sogou.com/weixin?type=2&s_from=input&query={}&_sug_=n&_sug_type_=&page=1'.format(parse.quote(key))
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0"
main_v4(url, UserAgent)

标签:__,搜狗,cookies,zh,para,url,re,params,uigs
From: https://www.cnblogs.com/thaimj1314520/p/16646537.html

相关文章

  • python serial报错问题
    参考一个python脚本,使用串口采集数据,但在执行时发现importserialimportserial.threaded有问题:解决方法很简单,使用pip命令执行pipinstallpyserial注意这里是pyse......
  • 学习 python进阶 类型提示
    python3.6后加入了新功能,用来声明一个变量的类型通过声明变量的类型,编辑器和一些功能给你提供更好的支持 容器类的需要引用typing包   ......
  • 设置VF聚合网口
    查看PCI网卡#lspci|grepEth19:00.0Ethernetcontroller:IntelCorporationEthernetControllerX710for10GbESFP+(rev02)19:00.1Ethernetcontroller:Int......
  • C# Eppuls 读取Excel System.OutOfMemoryException
    修改生成目标平台为64位因为在X86下默认最多使用内存是1.8GB 而64位下却没有该限制,我目前 数据是33W行52列左右. 修改完后问题解决参考  https://stackoverflow.......
  • Mp3tag for Mac(音频标签编辑器)中文版
    Mac哪款音频标签编辑工具好用呢?Mp3tagforMac是一款运行在MacOS上好用的音频标签编辑器。Mp3tagmac版可以快速对音频文件的元数据进行编辑修改,支持批量操作,涵盖MP3,MP4,M4V......
  • 关于docker创建容器报错-docker: Error response from daemon: runtime "io.container
    今天在对一台服务器(docker相关的业务服务器)进行OS补丁时,默认使用的yumupdate-y对所有的安装包进行了升级升级完成后,让应用方检查确认应用及功能是否一切正常,如果不正......
  • Educational Codeforces Round 134 (Rated for Div. 2)
    EducationalCodeforcesRound134(RatedforDiv.2)目录EducationalCodeforcesRound134(RatedforDiv.2)D.MaximumANDE.PrefixFunctionQueriesD.Maximum......
  • dubbo微服务链路追踪案例-skywalking
    zk10.0.0.7consumer10.0.0.13provider10.0.0.17skywalking10.0.0.4es10.0.0.2安装jdkwgethttps://download.oracle.com/java/18/latest/jdk-18_linux-x64_bin.......
  • prim
    朴素prim#include<bits/stdc++.h>usingnamespacestd;constintN=550,INF=0x3f3f3f3f;intn,m,dis[N],g[N][N];boolvis[N];intprim(){memset(di......
  • Go 语言入门 1-管道的特性及实现原理
    入坑go也快一年了,从今天开始会定期分享一下Go语言学习过程中的一些基础知识。 go语言中的管道,主要是用于协程之间的通信,比UNIX的管道更加轻量和易用。 我们......