python - 从Python中的大量字符串中读取引号内的子字符串
问题描述
我有以下字符串:
{"name":"INPROCEEDINGS","__typename":"PublicationConferencePaper"},"hasPermiss
ionToLike":true,"hasPermissionToFollow":true,"publicationCategory":"researchSu
mmary","hasPublicFulltexts":false,"canClaim":false,"publicationType":"inProcee
dings","fulltextRequesterCount":0,"requests":{"__pagination__":
[{"offset":0,"limit":1,"list":[]}]},"activeFiguresCount":0,"activeFigures":
{"__pagination__":[{"offset":0,"limit":100,"list":
[]}]},"abstract":"Heterogeneous Multiprocessor System-on-Chip (MPSoC) are
progressively becoming predominant in most modern mobile devices. These
devices are required to perform processing of applications within thermal,
energy and performance constraints. However, most stock power and thermal
management mechanisms either neglect some of these constraints or rely on
frequency scaling to achieve energy-efficiency and temperature reduction on
the device. Although this inefficient technique can reduce temporal thermal
gradient, but at the same time hurts the performance of the executing task.
In this paper, we propose a thermal and energy management mechanism which
achieves reduction in thermal gradient as well as energy-efficiency through
resource mapping and thread-partitioning of applications with online
optimization in heterogeneous MPSoCs. The efficacy of the proposed approach is
experimentally appraised using different applications from Polybench benchmark
suite on Odroid-XU4 developmental platform. Results show 28% performance
improvement, 28.32% energy saving and reduced thermal variance of over 76%
when compared to the existing approaches. Additionally, the method is able to
free more than 90% in memory storage on the MPSoC, which would have been
previously utilized to store several task-to-thread mapping
configurations.","hasRequestedAbstract":false,"lockedFields"
我正在尝试获取"abstract":"和","hasRequestedAbstract"之间的子字符串。为此,我使用以下代码:
import requests
#some more codes here........
to_visit_url = 'https://www.researchgate.net/publication/328749434_TEEM_Online_Thermal-_and_Energy-Efficiency_Management_on_CPU-GPU_MPSoCs'
this_page = requests.get(to_visit_url)
content = str(page.content, encoding="utf-8")
abstract = re.search('\"abstract\":\"(.*)\",\"hasRequestedAbstract\"', content)
print('Abstract:\n' + str(abstract))
但在抽象变量中,它的值是 None。可能是什么问题?如上所述,如何获取子字符串?
注意:虽然看起来我可以将其读取为 JSON 对象,但这不是一个选项,因为上面提供的示例文本只是完整 html 内容的一小部分,很难从中提取 JSON 对象。
PS页面的完整内容,即page.content,可以从这里下载:https ://docs.google.com/document/d/1awprvKsLPNoV6NZRmCkktYwMwWJo5aujGyNwGhDf7cA/edit?usp=sharing
或者也可以直接从 URL 下载源代码:https ://www.researchgate.net/publication/328749434_TEEM_Online_Thermal-_and_Energy-Efficiency_Management_on_CPU-GPU_MPSoCs
解决方案
re.search
不返回解析结果列表。它返回SRE_Match
对象。如果要获取匹配列表,则需要使用re.findall
方法。
测试代码
import re import requests test_pattern = re.compile('\"abstract\":\"(.*)\",\"hasRequestedAbstract\"') test_requests = requests.get("https://www.researchgate.net/publication/328749434_TEEM_Online_Thermal-_and_Energy-Efficiency_Management_on_CPU-GPU_MPSoCs") print(test_pattern.findall(test_requests.text)[0])
结果
'Heterogeneous Multiprocessor System-on-Chip (MPSoC) are progressively becoming predominant in most modern mobile devices. These devices are required to perform processing of applications within thermal, energy and performance constraints. However, most stock power and thermal management mechanisms either neglect some of these constraints or rely on frequency scaling to achieve energy-efficiency and temperature reduction on the device. Although this inefficient technique can reduce temporal thermal gradient, but at the same time hurts the performance of the executing task. In this paper, we propose a thermal and energy management mechanism which achieves reduction in thermal gradient as well as energy-efficiency through resource mapping and thread-partitioning of applications with online optimization in heterogeneous MPSoCs. The efficacy of the proposed approach is experimentally appraised using different applications from Polybench benchmark suite on Odroid-XU4 developmental platform. Results show 28% performance improvement, 28.32% energy saving and reduced thermal variance of over 76% when compared to the existing approaches. Additionally, the method is able to free more than 90% in memory storage on the MPSoC, which would have been previously utilized to store several task-to-thread mapping configurations.'
推荐阅读
- c++ - 新元素将插入到 std::set 的什么位置?
- android - Android 以编程方式打开所有控制绘制权限的应用程序的设置页面
- javascript - 处理javascript中的异步行为?
- javascript - 在 REST API 之后将 JavaScript 加载到 HTML
- ruby-on-rails - 更新文件集合活动存储
- python - 在天蓝色的 pip 上安装 _mysql 模块的问题
- android - 清单广播接收器未触发蓝牙事件
- javascript - 使用 defer 和 async 加载 JavaScript 文件
- php - 使用新的 Instagram Graph API 在网站上显示 Instagram 帐户照片
- active-directory - 我们如何在 Azure Databricks 中使用 Active Directory 身份验证连接 Azure SQL 数据库