python正则表达式问题!!
var microsoft = microsoft || {};microsoft.support = microsoft.support || {};
microsoft.support.prefetchedArticle = (function() {
return { 'zh-cn/4529964' : {
"sideNav": "4000816",
"releaseInfo": {
"releaseDate": "2019-11-12T00:00:00",
"releaseVersion": "Windows 10, version 1909 and Windows Server, version 1909"
},
"releaseNoteRelationship": {
"isMinorRelease": false,
"minorVersions": [
{
"id": "4550945",
"locale": "en",
"heading": "April 21, 2020—KB4550945 (OS Builds 18362.815 and 18363.815)",
"releaseDate": "2020-04-21T00:00:00",
"releaseVersion": "1903-OS Build 18362.815 and 1909-OS Build 18363.815"
},
{
"id": "4549951",
"locale": "zh-hans",
"heading": "2020 年 4 月 14 日 - KB4549951(操作系统内部版本 18362.778 和 18363.778)",
"releaseDate": "2020-04-14T00:00:00",
"releaseVersion": "1903-OS Build 18362.778 and 1909-OS Build 18363.778"
},
{
"id": "4554364",
"locale": "zh-hans",
"heading": "2020 年 3 月 30 日 - KB4554364(操作系统内部版本 18362.753 和 18363.753)",
"releaseDate": "2020-03-30T00:00:00",
"releaseVersion": "1903-OS Build 18362.753 and 1909-OS Build 18363.753"
},
{
"id": "4541335",
"locale": "zh-hans",
"heading": "2020 年 3 月 24 日 - KB4541335(操作系统内部版本 18362.752 和 18363.752)",
"releaseDate": "2020-03-24T00:00:00",
"releaseVersion": "1903-OS Build 18362.752 and 1909-OS Build 18363.752"
},
{
"id": "4551762",
"locale": "zh-hans",
"heading": "2020 年 3 月 12 日 - KB4551762(操作系统内部版本 18362.720 和 18363.720)",
"releaseDate": "2020-03-12T00:00:00",
"releaseVersion": "1903-OS Build 18362.720 and 1909-OS Build 18363.720"
},
{
"id": "4540673",
"locale": "zh-hans",
"heading": "2020 年 3 月 10 日 - KB4540673(操作系统内部版本 18362.719 和 18363.719)",
"releaseDate": "2020-03-10T00:00:00",
"releaseVersion": "1903-OS Build 18362.719 and 1909-OS Build 18363.719"
},
{
"id": "4535996",
"locale": "zh-hans",
"heading": "2020 年 2 月 27 日 - KB4535996(操作系统内部版本 18362.693 和 18363.693)",
"releaseDate": "2020-02-27T00:00:00",
"releaseVersion": "1903-OS Build 18362.693 and 1909-OS Build 18363.693"
},
{
"id": "4532693",
"locale": "zh-hans",
"heading": "2020 年 2 月 11 日 - KB4532693(操作系统内部版本 18362.657 和 18363.657)",
"releaseDate": "2020-02-11T00:00:00",
"releaseVersion": "1903-OS Build 18362.657 and 1909-OS Build 18363.657"
},
{
"id": "4532695",
"locale": "zh-hans",
"heading": "2020 年 1 月 28 日 - KB4532695(操作系统内部版本 18362.628 和 18363.628)",
"releaseDate": "2020-01-28T00:00:00",
"releaseVersion": "1903-OS Build 18362.628 and 1909-OS Build 18363.628"
},
{
"id": "4528760",
"locale": "zh-hans",
"heading": "2020 年 1 月 14 日 - KB4528760(操作系统内部版本 18362.592 和 18363.592)",
"releaseDate": "2020-01-14T00:00:00",
"releaseVersion": "1903-OS Build 18362.592 and 1909-OS Build 18363.592"
},
{
"id": "4530684",
"locale": "zh-hans",
"heading": "2019 年 12 月 10 日 - KB4530684(操作系统内部版本 18362.535 和 18363.535)",
"releaseDate": "2019-12-10T00:00:00",
"releaseVersion": "1903-OS Build 18362.535 and 1909-OS Build 18363.535"
},
{
"id": "4524570",
"locale": "zh-hans",
"heading": "2019 年 11 月 12 日 - KB4524570(操作系统内部版本 18362.476 和 18363.476)",
"releaseDate": "2019-11-12T00:00:00",
"releaseVersion": "1903-OS Build 18362.476 and 1909-OS Build 18363.476"
}
]
},
上诉这段代码抠不下来,我的正则表达是you问题吗?
url = 'https://support.microsoft.com/zh-cn/help/4529964/windows-10-update-history'
headers={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
#'Referer':"https://www.manhuadb.com/author/370"
}
web = requests.get(url,headers=headers)
gengxin = BeautifulSoup(web.text,'lxml')
dav = gengxin.find_all('script',type="text/javascript")
pan = re.compile('"releaseNoteRelationship": {.*?}')
for i in dav:
print(re.findall(pan,str(i)))
代码贴的都不想看 zdnyp 发表于 2020-4-24 14:10
代码贴的都不想看
不好意思,新手 我不知道则贴代码合适 为啥不直接解析成json 没转义? kesai 发表于 2020-4-24 14:15
为啥不直接解析成json
新手不知道该怎么做,怎么解析??JSON hahawangzi 发表于 2020-4-24 14:28
新手不知道该怎么做,怎么解析??JSON
参考这个,https://www.jianshu.com/p/1f13e93e6ab8 试过了 不行的报错web = requests.get(url,headers=headers)
gengxin = BeautifulSoup(web.text,'lxml')
dict_j = json.loads(web.text)
print(dict_j)
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 2) hahawangzi 发表于 2020-4-24 14:55
试过了 不行的报错web = requests.get(url,headers=headers)
gengxin = BeautifulSoup(web.text,'lxml')
...
应该是因为不是标准的json格式,所以会报错 基本功弄好~json decode、encode。你可以先截一小段做尝试,不用一大段代码来尝试。。发帖问题表述清楚一点,没看出你要正则些什么玩意
页:
[1]
2