如何使用Beautifutdsoup在Python中找到特定的课程
来自< e节</span> land</h2>
我只是在提取class =“ H1”
因为我需要在此< span ID =“ Ref613779”之间的字符串问题是,它没有给我所有出现的结果
class =“ h1”
它只是为我首次出现的结果提供了结果class =“ H1”
class ='h1
in < e节h1“>< span id =“ Ref613784”></span>/h2>
这里网站链接https://www.britannica.com/place/alabama-state
我尝试从该网站(htmlcontent)中提取该字符串,超过两个出现class = 'H1
,但我只是从该网站给您两个示例。
我的代码:
from bs4 import BeautifulSoup
import requests
htmlrequests=requests.get('https://www.britannica.com/place/Alabama-state')
htmlcontent=htmlrequests.content
soup=BeautifulSoup(htmlcontent,'html.parser')
for section in soup.find_all(class_='h1'):
print(section.text)
输出是:land
和预期land
人
足以解释我的问题,等待您的解决方案吗
From <section id="ref78299" data-level="1" data-has-spy="true"><h2 class="h1"><span id="ref613779"></span>Land</h2>
I am just extracting class="h1"
because I need string between this <span id="ref613779"></span>Land</h2>
and its working but the problem is that its not giving me results for all occurrence class="h1"
its just gave me a result for a first occurrence of class="h1"
Hower occurrence of class='h1
in <section id="ref273744" data-level="1" data-has-spy="true"><h2 class="h1"><span id="ref613784"></span>People</h2>
Here website link https://www.britannica.com/place/Alabama-state
from which I am trying to extract that string at that website(htmlcontent) more than two occurrence of class='h1
but I am just giving you a example of two from that website.
My code:
from bs4 import BeautifulSoup
import requests
htmlrequests=requests.get('https://www.britannica.com/place/Alabama-state')
htmlcontent=htmlrequests.content
soup=BeautifulSoup(htmlcontent,'html.parser')
for section in soup.find_all(class_='h1'):
print(section.text)
and output is:Land
and expected Land
People
is it enough to explain my problem ,waiting for your solution
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是你想要的吗?
结果:
Is this what you want?
Result: