如何在python beautiful soup中提取此文本

2024-09-26 18:01:04 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在python beautiful soup中提取这个文本(它是从<p></p>的摘要)?你知道吗

<div>
      <div class="o-media__body">
          <span class="text-bolder text-larger">Summary</span>
      </div>
      <div>
           <p>Hello, I m from Europe Macedonia, I came to USA 12 years ago, i got my citizenship 7 years ago, I m very happy person, i like to help people, I don't like to change jobs.In my life I worked only 3 jobs, First job I worked as a Nurse in Macedonia for 7 years, and I had to leave as i came to USA. Then I found a job in Wisconsin as a teacher at the Day care, I worked there for 6 years, I had to leave as i moved to Reno, NV. In Reno I start working at Disability Attorney's office, we were helping people to apply for disability i worked there for 5 years, I like to go to work everyday, and i like to do my job right, if i don't understand something I will ask for help, I believe is better ask then make mistakes. I lost my job after i returned from my vacation, i don't know the reason, I have a good recommendation letter from my previous job.
          </p>
    </div>
</div>

我试过这个,但它只给出摘要作为输出

soup_data.find("span", { "class" : "text-bolder text-large" })

如何提取嵌套标记?你知道吗


Tags: totextfromdivformyasjob
1条回答
网友
1楼 · 发布于 2024-09-26 18:01:04

我通常使用select(),因为我喜欢类似jQuery的语法,但这只是我自己。你知道吗

使用URL from your comment

text = soup_data.select("div.panel-body > p")[0].get_text()

text将包含:

"Hello, I m from Europe Macedonia, I came to USA 12 years ago, i got my citizenship 7 years ago, I m very happy person, i like to help people, I don't like to change jobs.In my life I worked only 3 jobs, First job I worked as a Nurse in Macedonia for 7 years, and I had to leave as i came to USA. Then I found a job in Wisconsin as a teacher at the Day care, I worked there for 6 years, I had to leave as i moved to Reno, NV. In Reno I start working at Disability Attorney's office, we were helping people to apply for disability i worked there for 5 years, I like to go to work everyday, and i like to do my job right, if i don't understand something I will ask for help, I believe is better ask then make mistakes. I lost my job after i returned from my vacation, i don't know the reason, I have a good recommendation letter from my previous job."

相关问题 更多 >

    热门问题