Python BeautifulSoup4:找不到';a';通过find()使用特定href值标记

Python BeautifulSoup4:找不到';a';通过find()使用特定href值标记,python,html,beautifulsoup,web-crawler,Python,Html,Beautifulsoup,Web Crawler,我正在尝试用python3从中抓取实时比特币港币 我发现在HTML中具体定位它的唯一方法是使用href=“/pt pt/price/bitcoin” 但是,它总是返回secBitcoin=None。没有匹配的结果 当我使用class参数搜索'div'标签时,find函数工作得很好 我也尝试过类似的格式 .find('a[href="/pt-PT/price/bitcoin"]') 但是什么都不起作用。在初始页面加载之后,页面可能正在加载货币值。您可以尝试按ctrl+s键保存

我正在尝试用python3从中抓取实时比特币港币

我发现在HTML中具体定位它的唯一方法是使用href=“/pt pt/price/bitcoin”

但是,它总是返回secBitcoin=None。没有匹配的结果

当我使用class参数搜索'div'标签时,find函数工作得很好

我也尝试过类似的格式

.find('a[href="/pt-PT/price/bitcoin"]')

但是什么都不起作用。

在初始页面加载之后,页面可能正在加载货币值。您可以尝试按ctrl+s键保存完整网页并打开该文件,而不是使用请求。如果这也不起作用,那么我不确定问题出在哪里。
如果这确实有效,那么您可能需要使用selenium之类的工具来获取所需的内容

href是元素的属性,因此我认为您无法通过这种方式找到它

def is_a_and_href_matching(element):
   is_a = element.name == a
   
   if is_a and element.has_attr(href):
      if element['href'] == "/pt-PT/price/bitcoin":
         return True
   return False

secBitcoins=root.find_all(is_a_and_href_matching)
for secBitcoin in secBitcoins:
   p = setBitcoin.find('p')
.find('a[href="/pt-PT/price/bitcoin"]')
def is_a_and_href_matching(element):
   is_a = element.name == a
   
   if is_a and element.has_attr(href):
      if element['href'] == "/pt-PT/price/bitcoin":
         return True
   return False

secBitcoins=root.find_all(is_a_and_href_matching)
for secBitcoin in secBitcoins:
   p = setBitcoin.find('p')