如何使用beauthulsoup python在嵌套div中查找类

2024-04-19 11:48:48 发布

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

我现在正在研究网络爬虫,似乎我无法从某个特定的网站上获得div中的类。下面是我的代码。我在Python3中使用了美容组

import requests
from bs4 import BeautifulSoup as bs

response = requests.get('https://e27.co/startup/flipkart').text
soup = bs(response, 'html.parser')
content_div = soup.findAll('h1',class_ = 'profile-startup')
print(content_div)

我想提取h1中的文本,该文本具有类“profile start”。以上代码不返回任何内容。你们能帮我吗?


Tags: 代码文本import网络divbs网站response
1条回答
网友
1楼 · 发布于 2024-04-19 11:48:48

这个网站正在使用Javascript填充数据。如果您查看response中的内容,您将看到没有h1。您必须查看他们是否有一个API,您可以使用它来检索所需的信息,或者考虑使用像Selenium这样的浏览器自动化技术:http://selenium-python.readthedocs.io/installation.html#introduction

相关问题 更多 >