如何从美丽的群岛中提取Li?

发布于 2025-02-07 08:31:03 字数 528 浏览 0 评论 0原文

我知道这个问题似乎很基本,但我似乎无法从给定的ULS中提取LI和文本。

https://solar.world.org/reuse/aluminum.foil

这是这里我想提取的URL。我尝试使用Find_all作为UL,但这给了我一个奇怪的回报结果,我无法使用它来从LI中提取任何文本。

从理论上讲,此代码应该起作用。

page = requests.get('https://solar.world.org/reuse/Aluminum.Foil')
soup = BSoup(page.content, 'html.parser')

for i in soup.find_all('ul'):
    for j in i.find_all('li'):
        print(j.text)

但不是。

I know the question may seem very basic but I can't seem to extract the li and the text from the given uls.

https://solar.world.org/reuse/Aluminum.Foil

Here is the url I am trying to extract. I have tried using find_all for ul but that gives me a weird return result and I can't use it to extract any text from the li.

In theory this code should work.

page = requests.get('https://solar.world.org/reuse/Aluminum.Foil')
soup = BSoup(page.content, 'html.parser')

for i in soup.find_all('ul'):
    for j in i.find_all('li'):
        print(j.text)

but its not.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栀梦 2025-02-14 08:31:03

该页面的格式不好(不是您的错)。使用更好的解析器来解析它:

soup = BSoup(page.content, 'html5')

The page has very bad formatting (not your fault). Use a better parser to parse it:

soup = BSoup(page.content, 'html5')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文