I need to extract an image src URL from an external website. For example from this URL: enter link description here
the source image URL of interest is img id = "cur-moon" and then assign the image URL to one of my HTML img tag. The reason I need this function is that the image source url (of id "cur-moon") will change over time.
So far I've seen a lot of examples to get it from within the same HTML code itself, not from an external web page.
Solution: Never mind. I managed to get it with bash script commands which eventually download the correct Moon phase image from the website. The image will be referenced to by my websites. These are the commands:
# to search for /scripts/moon.php?i=0.288&p=4.628&r=4.600
# find keyword "id=cur-moon src=" and get all next characters till found " but not including "
x=$(wget -O - https://www.timeanddate.com/moon/phases/thailand/bangkok | grep -oP 'id=cur-moon src="\K[^"]+')
# replace amp; with null; so get /scripts/moon.php?i=0.288&p=4.628&r=4.600
y=$(echo $x | sed 's/amp;//g')
echo https://www.timeanddate.com${y}
# saving current moon phase image (phase is correct, but it always orients vertically)
wget -O moonphase.png https://www.timeanddate.com${y}