如何使用 Beautiful Soup 从 href 标签下的 <strong> 标签中提取字符串?

时间:2021-07-14 06:25:32

标签: python web-scraping

我正在尝试抓取此 [1] 网页。我想提取字符串“WORK FROM HOME,PACKING”。我是 无法使用下面的代码访问强标签。我使用的是 Beautiful Soup。

 job = soup.find('li', class_='clearfix job-bx wht-shd-bx')

 job_name = job.header.h2.a.find_all('strong',_class="blkclor")

 print(job_name)
<块引用>

结果 = [](无)

<块引用>

预期结果:在家工作,打包

这是链接 [1] https://www.timesjobs.com/candidate/job-search.html?searchType=personalizedSearch&from=submit&txtKeywords=work+from+home&txtLocation=

1 个答案:

答案 0 :(得分:0)

这应该有效。

r = requests.get("https://www.timesjobs.com/candidate/job-search.html?searchType=personalizedSearch&from=submit&txtKeywords=work+from+home&txtLocation=")

b = BeautifulSoup(r.content)

for i in b.select("h2>a"):
    print(i.text.strip())
相关问题