gpt4 book ai didi

python - 通过Python解析URL

转载 作者:行者123 更新时间:2023-12-01 04:45:41 25 4
gpt4 key购买 nike

我需要解析

http://www.webpagetest.org/breakdown.php?test=150325_34_0f581da87c16d5aac4ecb7cd07cda921&run=2&cached=0

如果您查看上述网址的来源,您会发现

预期输出:

fvRequests= css
fvRequests=7

最佳答案

import re
import urllib2



if __name__ == "__main__":
url = 'http://www.webpagetest.org/breakdown.php?test=150325_34_0f581da87c16d5aac4ecb7cd07cda921&run=2&cached=0'

# http request
response = urllib2.urlopen(url)
html = response.read()
response.close()

# finding values in html
results = re.findall(r'fvRequests\.setValue\(\d+, \d+, \'?(.*?)\'?\);', html)
keys = results[::2]
values = results[1::2]

# creating a dictionary
output = dict(zip(keys, values))

print output

关于python - 通过Python解析URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29454689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com