Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用beautifulsoup对aria标签进行数据抓取_Python_Html_Web Scraping_Beautifulsoup - Fatal编程技术网

Python 使用beautifulsoup对aria标签进行数据抓取

Python 使用beautifulsoup对aria标签进行数据抓取,python,html,web-scraping,beautifulsoup,Python,Html,Web Scraping,Beautifulsoup,从以下内容中,我试图提取分析师的价格目标。 我对aria标签中的信息感兴趣 我使用以下设置尝试了联机找到的多个版本的BeautifulSoup: import requests from bs4 import BeautifulSoup headers = {'User-Agent' : 'XXXXX'} >> XXXXX replaced with actual url = 'https://finance.yahoo.com/quote/AAPL/analysis?p=AAPL'

从以下内容中,我试图提取分析师的价格目标。 我对aria标签中的信息感兴趣

我使用以下设置尝试了联机找到的多个版本的
BeautifulSoup

import requests
from bs4 import BeautifulSoup
headers = {'User-Agent' : 'XXXXX'} >> XXXXX replaced with actual
url = 'https://finance.yahoo.com/quote/AAPL/analysis?p=AAPL'
r = requests.get(url, headers=headers)
soup = BeautifulSoup(r.text, 'html.parser')
  • aria标签似乎介于
    'div'
    'class'
    之间,因此我尝试了以下方法:

      target = soup.find('div', {'class':'Px(10px)'})
    
      target = soup.find('section', attrs={'data-test':'price-targets'})
    
  • 结果=无

  • 它位于一个分区内,因此我尝试了以下操作:

      target = soup.find('div', {'class':'Px(10px)'})
    
      target = soup.find('section', attrs={'data-test':'price-targets'})
    
  • 结果=无

  • 然后,我尝试使用ID向上移动:

      target = soup.find('div', {'id':'mrt-node-Col2-5-QuoteModule'}).find_all('div')[0]
    
  • 结果=

    因此,我越来越接近选项3,但当我修改
    find_all
    div索引时收到一个错误

    提取aria标签中的4个数据是否有任何解决方案或周转

    我的目标是
    'Low'
    'Current'
    'Average'
    'High'
    旁边的数字


    正如@Ann Zen在评论中提到的,该网站正在动态呈现元素和数据,
    Beautifulsoup
    无法单独使用
    Selenium来处理它,Selenium
    将等待应用程序加载后再尝试获取元素


    示例

    由于
    selenium
    可能需要花费时间进行迭代,我找到了第二种可能的解决方案,即使用
    请求
    获取页面的源代码,并使用json和regex组合搜索数据。

    您能发布URL吗?感谢您编辑我的第一篇帖子!我发布了URL,您需要使用
    selenium
    ,因为您尝试获取的元素是动态的,
    Beautifulsoup
    无法处理动态html。请使用selenium给出一个解决方案:)@AnnZen我正在使用:-)@utpaldut非常感谢您提供的信息!我将开始学习硒,同时等待您的解决方案:)