鱼C论坛

 找回密码
 立即注册
查看: 1407|回复: 1

[已解决]如何将标签内部文本和标签文本合并

[复制链接]
发表于 2020-7-13 00:06:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
如题,希望将strong标签内的文字Background和P标内的文字several合并从成:Background:several的形式
附上代码:
for soul_select_item in soul_select2:           #获得abstract,soul_select2:为beautifulsoup选择后的列表
    if len(soul_select_item) == 1:
        print('该文章的摘要为:{}'.format(str(soul_select_item.get_text()).strip()))
    elif len(soul_select_item) == 0:
        print('该文章无摘要')
    else:
        print('该文章综合摘要的:')
        for soul_select_item_1 in soul_select_item:
            print('{}'.format(str(soul_select_item_1.string).strip()))





附上结果:
该文章链接为:https://pubmed.ncbi.nlm.nih.gov/32649742/
该文章的DOI为:10.1093/ajcn/nqaa152
该文章综合摘要的:

Background:
Several countries have notably reduced childhood stunting relative to economic growth over the past 15-20 y. The Exemplars in Stunting Reduction project, or "Exemplars," studies success factors among these countries with a lens toward replicability.
该文章综合摘要的:

Objectives:
This paper details the standardized mixed-methods framework for studying determinants of childhood stunting reduction applied in Exemplars studies.



附上网页源代码:
<p>

      <strong class="sub-title">
        Background:
      </strong>



      Several countries have notably reduced childhood stunting relative to economic growth over the past 15-20 y. The Exemplars in Stunting Reduction project, or "Exemplars," studies success factors among these countries with a lens toward replicability.



  </p>

最佳答案
2020-7-13 08:32:50


这样可否?
import re
import requests

url = 'https://pubmed.ncbi.nlm.nih.gov/32649742/'
headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'
}
request = requests.get(url,headers=headers)
html = request.text
titles = re.findall(r'<strong .+\s* (.+:)',html)
contents = re.findall(r'</strong>\s*(.+\.)',html)

for x,y in zip(titles,contents):
    print(x+y)

运行结果:
Background:Several countries have notably reduced childhood stunting relative to economic growth over the past 15-20 y. The Exemplars in Stunting Reduction project, or "Exemplars," studies success factors among these countries with a lens toward replicability.
Objectives:This paper details the standardized mixed-methods framework for studying determinants of childhood stunting reduction applied in Exemplars studies.
Methods:An expert technical advisory group (TAG), criteria for identifying Exemplar countries, evidence-based frameworks, mixed methodologies (quantitative, qualitative, policy, literature review), effective research partnerships, case study process and timeline, and data triangulation and corroboration are presented.
Results:Experts in health, nutrition, and evaluation methods were selected at the study outset to provide technical support to all phases of research (TAG). Exemplar countries were selected by the TAG, who considered quantitative data (e.g., annual rates of stunting change compared with economic growth, country population size) and qualitative insights (e.g., logistics of country work, political stability). Experienced country research partners were selected and an inception meeting with stakeholder consultations was held to launch research and garner support. Evidence-based conceptual frameworks underpinned all Exemplars research activities. A systematic review of published peer-reviewed and grey literature was undertaken, along with in-depth policy and program analysis of nutrition-specific and -sensitive investments. Both descriptive and advanced quantitative analysis was undertaken (e.g., equity analyses, difference-in-difference regression, Oaxaca-Blinder decomposition). Qualitative data collection using in-depth interviews and focus groups was conducted with national and community stakeholders (i.e., child care workers and mothers) to understand country experiences. The case study process was iterative, and all research outputs were triangulated to develop the stunting reduction narrative for each country. Findings were shared with country experts for weigh-in and corroboration through dissemination events.
Conclusions:Exemplars research uses a mixed-methods framework for studying positive outliers that can be applied across diverse health and development outcomes.
Keywords:children; determinants; drivers; exemplar; framework; linear growth; mixed methods; stunting.

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-7-13 08:32:50 | 显示全部楼层    本楼为最佳答案   


这样可否?
import re
import requests

url = 'https://pubmed.ncbi.nlm.nih.gov/32649742/'
headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'
}
request = requests.get(url,headers=headers)
html = request.text
titles = re.findall(r'<strong .+\s* (.+:)',html)
contents = re.findall(r'</strong>\s*(.+\.)',html)

for x,y in zip(titles,contents):
    print(x+y)

运行结果:
Background:Several countries have notably reduced childhood stunting relative to economic growth over the past 15-20 y. The Exemplars in Stunting Reduction project, or "Exemplars," studies success factors among these countries with a lens toward replicability.
Objectives:This paper details the standardized mixed-methods framework for studying determinants of childhood stunting reduction applied in Exemplars studies.
Methods:An expert technical advisory group (TAG), criteria for identifying Exemplar countries, evidence-based frameworks, mixed methodologies (quantitative, qualitative, policy, literature review), effective research partnerships, case study process and timeline, and data triangulation and corroboration are presented.
Results:Experts in health, nutrition, and evaluation methods were selected at the study outset to provide technical support to all phases of research (TAG). Exemplar countries were selected by the TAG, who considered quantitative data (e.g., annual rates of stunting change compared with economic growth, country population size) and qualitative insights (e.g., logistics of country work, political stability). Experienced country research partners were selected and an inception meeting with stakeholder consultations was held to launch research and garner support. Evidence-based conceptual frameworks underpinned all Exemplars research activities. A systematic review of published peer-reviewed and grey literature was undertaken, along with in-depth policy and program analysis of nutrition-specific and -sensitive investments. Both descriptive and advanced quantitative analysis was undertaken (e.g., equity analyses, difference-in-difference regression, Oaxaca-Blinder decomposition). Qualitative data collection using in-depth interviews and focus groups was conducted with national and community stakeholders (i.e., child care workers and mothers) to understand country experiences. The case study process was iterative, and all research outputs were triangulated to develop the stunting reduction narrative for each country. Findings were shared with country experts for weigh-in and corroboration through dissemination events.
Conclusions:Exemplars research uses a mixed-methods framework for studying positive outliers that can be applied across diverse health and development outcomes.
Keywords:children; determinants; drivers; exemplar; framework; linear growth; mixed methods; stunting.

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-20 01:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表