下午好!如何让Beautifulsoup只抓取多组“[:”和“:]”之间的内容到目前为止,我已经在我的soup中获得了整个页面,但遗憾的是,它没有标记。你知道吗
到目前为止,我已经尝试了一些方法:
soup.findAll(text="[")
keys = soup.find("span", attrs = {"class": "objectBox objectBox-string"})
import bs4 as bs
import urllib.request
source = urllib.request.urlopen("https://login.microsoftonline.com/common/discovery/keys").read()
soup = bs.BeautifulSoup(source,'lxml')
# ---------------------------------------------
# prior script that I was playing with trying to tackle this issue
import requests
import urllib.request
import time
from bs4 import BeautifulSoup
# Set URL to scrape new certs from
newcerts = "https://login.microsoftonline.com/common/discovery/keys"
# Connect to the URL
response = requests.get(newcerts)
# Parse HTML and save to BeautifulSoup Object
soup = BeautifulSoup(response.text, "html.parser")
keys = soup.find("span", attrs = {"class": "objectBox objectBox-string"})
最终目标是从Azure的网站https://login.microsoftonline.com/common/discovery/keys检索公共PKI密钥
您从该url获得的数据已经被结构化为Json或python dict格式。 我将通过请求获取数据,并使用ast将其从字符串转换为dict格式。你知道吗
让我举个例子:
从这里开始,您可以使用python中dict的一些知识来访问每个值。你知道吗
不知道这是不是你想要的。请尝试以下脚本:
相关问题 更多 >
编程相关推荐