Posted in
8
6:56 am, April 4, 2021
python extract images into an array from a url
this should extract all images from a url into an array using python
python
from bs4 import BeautifulSoup
from urllib.request import urlopen
url = "https://www.kruxor.com/view/code/LOveX/"
page = urlopen(url)
html = page.read().decode("utf-8")
soup = BeautifulSoup(html, "html.parser")
#print(soup.get_text())
images = soup.find_all("img")
print(images)
return result
[<img src="https://www.kruxor.com/images/change%20the%20cursor%20to%20a%20pointer%20for%20an%20element.gif"/>, <img src="https://www.kruxor.com/images/ios-14-iphone.jpg"/>]
extract the 1st image src only rather than the full img tag
add this instead of print(images)
python
images_src = images[0]["src"];
print(images_src)
View Statistics
This Week
38
This Month
243
This Year
0
Add Comment
Other Items in python
Related Search Terms
Other Categories in Code
c testing apache apps asp bat bootstrap bootstrap templates core css css grid design elements fancybox fonts foundation framework gimp git html icons ideas images javascript jquery js linux mac nginx node php php functions php simple html dom pi400 python react sections site bugs site documentation sql sqlite sublime svg templates tools virtual box webdev windows wordpress