Python Forum
How can I web scrape the "alt" attribute from a "img" tag with Python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I web scrape the "alt" attribute from a "img" tag with Python?
#2
Images(svg) are just use as backgrounds,need to parse the values needed.
A example.
import bs4, requests, webbrowser

LINK = "https://www.meteo.it/meteo/roma-oggi-58091"
response = requests.get(LINK)
response.raise_for_status()
soup = bs4.BeautifulSoup(response.content, 'html.parser')
# can just copy CSS selector from browser(inspect Dev Tools)
weather_info = soup.select_one('#main-locations > nav > div > div:nth-child(1)')  
>>> weather_info.text
'Roma27°'
>>> weather_info.p.text
'Roma'
>>> weather_info.p.next_sibling.text
'27°'
>>> # The image used as background for tag over
>>> weather_info.img.get('src')
'//w-static.meteosuper.it/public/icons/ic_cloudy_day_100px_10_26.svg
Reply


Messages In This Thread
RE: How can I web scrape the "alt" attribute from a "img" tag with Python? - by snippsat - Aug-19-2022, 04:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Lightbulb Python Obstacles | Kung-Fu | Full File HTML Document Scrape and Store it in MariaDB BrandonKastning 5 3,143 Dec-29-2021, 02:26 AM
Last Post: BrandonKastning
  Python Obstacles | American Kenpo | Wiki Scrape URL/Table and Store it in MariaDB BrandonKastning 6 3,075 Dec-29-2021, 12:38 AM
Last Post: BrandonKastning
  Python Obstacles | Karate | HTML/Scrape Specific Tag and Store it in MariaDB BrandonKastning 8 3,408 Nov-22-2021, 01:38 AM
Last Post: BrandonKastning
  Beautifulsoup doesn't scrape page (python 2.7) Hikki 0 2,098 Aug-01-2020, 05:54 PM
Last Post: Hikki
  scrape data 1 go to next page scrape data 2 and so on alkaline3 6 5,613 Mar-13-2020, 07:59 PM
Last Post: alkaline3
  Scrape ASPX data with python... hoff1022 0 4,624 Feb-26-2019, 06:16 PM
Last Post: hoff1022
  [Python / BS4] How to Scrape digitalmatic7 9 10,187 Oct-21-2017, 12:55 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020