Python:使用Beauty Soup从HTML标记中提取图像源
我正在尝试单独打印图像Src标记值,我可以成功打印图像标记值,但无法获得Src标记值Python:使用Beauty Soup从HTML标记中提取图像源,python,beautifulsoup,Python,Beautifulsoup,我正在尝试单独打印图像Src标记值,我可以成功打印图像标记值,但无法获得Src标记值 import urllib3 import certifi from urllib3 import PoolManager from bs4 import BeautifulSoup urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) manager=PoolManager(num_pools=3,cert_reqs='CER
import urllib3
import certifi
from urllib3 import PoolManager
from bs4 import BeautifulSoup
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
manager=PoolManager(num_pools=3,cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where())
base_url="https://app.tipotapp.com/docs/quickstart/"
page=manager.request('GET',base_url)
soup = BeautifulSoup(page.data, 'html.parser')
idd='creating-an-application'
for sibling in soup.find(id=idd).next_siblings:
if sibling.name is None :
continue
elif sibling.name != 'h2' :
print(sibling.getText())
if sibling.img is not None:
print(sibling.img)
#print(sibling.select_one("img"))
else:
continue
else :
break
我现在得到的输出是
印刷品:
…某些预期字符串。。。。然后是下面的输出
<img alt="Student Management System"
src="https://app.tipotapp.com/docs/images/quickstart/image_004.png"/>
在这种情况下,我只想打印src值。要获取属性的值,请使用该方法
tag[key]
返回标记的“key”属性值,如果不存在,则抛出异常
只需将行print(sibling.img)
替换为
print(sibling.img['src'])
输出:
https://app.tipotapp.com/docs/images/quickstart/image_002.png
https://app.tipotapp.com/docs/images/quickstart/image_002_1.png
https://app.tipotapp.com/docs/images/quickstart/image_004.png