首页 > 解决方案 > Python:我如何得到

背景图像 url 值

问题描述

目前我正在使用下面的代码来获取页面上的所有 img 标签。我可以以某种方式访问​​ background-img url 值吗

import random
import urllib.request
import requests
from bs4 import BeautifulSoup


#1. Reading pages
source = requests.get("https://www.dummie-website/photos_all").text
soup = BeautifulSoup(source,'lxml')

    enter code here

#2. Getting every 'src' value from all img tags
match = [x['src'] for x in soup.findAll('img', {'class': ''})]

for i in match:
  print(i) 

标签: python

解决方案


推荐阅读