简体   繁体   English

从 html 中提取图像 url

[英]Extract image url from html

<div class="col-lg-2 col-md-2 vcenter no-pad-top no-pad-bot">
<img itemprop="image" src="/uploads/images/cache/20955226c5c975c230cb8e1f8cff0e6f1583249561_150_150.png" alt="SPINNEY MOBILE DEVELOPMENT" class="b-lazy pull-left center-block img-responsive b-loaded"></div>

I need to extract image from this particular class only我只需要从这个特定的 class 中提取图像

"/uploads/images/cache/20955226c5c975c230cb8e1f8cff0e6f1583249561_150_150.png"

My code:我的代码:

url = "https://www.appfutura.com/developers/spinney"
html = urlopen(url).read()
soup = BeautifulSoup(html,"lxml")
soup.prettify()

for link in soup.find_all('img'):
    print(link.get('src'))

how can i Acheive further task?我怎样才能完成进一步的任务? please help请帮忙

If I understood your question correctly:如果我正确理解了您的问题:

When printing img "src" attribute you can check whether it contains "/uploads/images/cache/" or not.打印 img “src” 属性时,您可以检查它是否包含“/uploads/images/cache/”。

img = soup.find_all('img')

for link in img:
    if "/uploads/images/cache/" in link.get('src'):
         print(link.get('src'))

there is a module called 'webbrowser' which lets you open a url, such as:有一个名为“webbrowser”的模块可让您打开 url,例如:

import webbrowser
url = "https://www.appfutura.com/developers/spinney"
webbrowser.open(url)

but to DOWNLOAD a url you must import requests但要下载 url 您必须导入请求

import requests


url = 'https://www.appfutura.com/developers/spinney'
r = requests.get(url, allow_redirects=True)

open('yoururlname.html', 'wb').write(r.content)

if you created a folder with that program, the download will end up in your folder.如果您使用该程序创建了一个文件夹,则下载将最终在您的文件夹中。 the program will be just a black screen popping up and closing, and the url will be downloaded该程序将只是一个黑屏弹出和关闭,url 将被下载

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM