宁波大学提取网页源代码加了盐的值

import requests
import re
def getHTMLText(url):
    try:
        headers={
            'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
            'Accept-Encoding':'gzip,deflate,br',
            'Accept-Language':'zh-CN,zh;q=0.9',
            'Cache-Control':'no-cache',
            'Connection':'keep-alive',
            'Cookie':'JSESSIONID_auth=uGTw7nB72ZxHRaBB6JV1_nvSr1B5Ixe0aJ54vss58t5OwmTqaSfj!832266270;SF_cookie_6=93395001',
            'Host':'uis.nbu.edu.cn',
            'Pragma':'no-cache',
            'sec-ch-ua':'"Chromium";v="92","NotA;Brand";v="99","GoogleChrome";v="92"',
            'sec-ch-ua-mobile':'?0',
            'Sec-Fetch-Dest':'document',
            'Sec-Fetch-Mode':'navigate',
            'Sec-Fetch-Site':'none',
            'Sec-Fetch-User':'?1',
            'Upgrade-Insecure-Requests':'1',
            'User-Agent':'Mozilla/5.0(WindowsNT6.1)AppleWebKit/537.36(KHTML,likeGecko)Chrome/92.0.4515.107Safari/537.36'
        }
        r=requests.get(url,headers=headers,timeout=60)
        print(r.status_code)
        r.raise_for_status()
        r.encoding='utf-8'
        return r.text
    except:
        print('url:',url)
url="https://uis.nbu.edu.cn/authserver/login"
html=getHTMLText(url)
pattern=r'(?<=var pwdDefaultEncryptSalt = ")(.+?)(?=";)'
name_list=re.findall(pattern,html)[0]
print(name_list)
import re
headers_str="""

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cache-Control: no-cache
Connection: keep-alive
Cookie: JSESSIONID_auth=uGTw7nB72ZxHRaBB6JV1_nvSr1B5Ixe0aJ54vss58t5OwmTqaSfj!832266270; SF_cookie_6=93395001
Host: uis.nbu.edu.cn
Pragma: no-cache
sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"
sec-ch-ua-mobile: ?0
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?1
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36

"""

pattern='^(.*?):(.*)$'
for line in headers_str.splitlines():
    print(re.sub(pattern,'\'\\1\':\'\\2\',',line).replace(" ",""))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值