正则表达式匹配不到值
re.search(r'window.__INITIAL_STATE__ = (.*)',r.text)匹配到是空的
{"Initialization":"0-919","indexRange":"920-1731"},"segment_base":{"initialization":"0-919","index_range":"920-1731"},"codecid":0}]},"support_formats":[{"quality":64,"format":"flv720","new_description":"720P 高清","display_desc":"720P","superscript":""},{"quality":32,"format":"flv480","new_description":"480P 清晰","display_desc":"480P","superscript":""},{"quality":16,"format":"flv360","new_description":"360P 流畅","display_desc":"360P","superscript":""}],"high_format":null},"session":"bc46ce7a7a3f982ace462fc2671c7afd"}</script>
<script>window.__INITIAL_STATE__={"aid":20808172,"bvid":"BV1YW411p7jo","p":1,"episode":"","videoData":{"bvid":"BV1YW411p7jo","aid":20808172,"videos":1,"tid":59,"tname":"演奏","copyright":1,"pic":"http:\u002F\u002Fi0.hdslb.com\u002Fbfs\u002Farchive\u002F36b74797821e29a84ed3253e5f65feb88e0f961b.jpg","title":"
得到网页之后,用正则找到所需要的数据,不是这样写的吗,我向提取出window.__INITIAL_STATE__ 这个字典,为什么是空值呢 发完整代码 re.search(r'window.__INITIAL_STATE__=(.*)',r.text)
等于号前后不应该有空格,不是赋值操作,等于号左边是左边界,左边界的内容必须跟返回的文本一模一样,不能随意加空格,右边也是
另外看你的返回结果用json去解析可能更方便 redforce 发表于 2021-8-22 15:50
re.search(r'window.__INITIAL_STATE__=(.*)',r.text)
等于号前后不应该有空格,不是赋值操作,等于号左边 ...
谢谢大佬,问题解决了{:10_332:}
页:
[1]