【问题标题】:How to find class inside nested div using BeautifulSoup python如何使用 BeautifulSoup python 在嵌套 div 中查找类
【发布时间】:2017-06-21 16:03:12
【问题描述】:

我现在正在研究网络爬虫,似乎我无法从特定网站获取 div 内的类。下面是我的代码。我在 Python3 中使用 BeautifulSoup

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-startup”类的文本。上面的代码什么也不返回。你们能帮帮我吗?

【问题讨论】:

    标签: python html python-3.x beautifulsoup web-crawler


    【解决方案1】:

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

    【讨论】:

    • 感谢您的帮助!我会尝试使用 Selenium!
    猜你喜欢
    • 2018-03-25
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    • 2020-12-04
    • 1970-01-01
    • 2019-06-04
    • 1970-01-01
    相关资源
    最近更新 更多