Reputation: 797
I have a wordpress site that has a plugin installed to scrape a weather reading from an external website, however, I don't like the graphics that site uses in the weather content.
I would like to know if there is a script that I can use to detect the path of the graphic and change it to the path I specify.
eg:
if image source (<img src="">
) contains "http://resources.weatherzone.com.au/wz/images/icons/fcast_70/"
then replace image source with "http://mywebsite.com/images/"
The thing is… the content changes with the weather, so the graphic may be dynamically updated. So I'd need to replace the path ONLY, leaving the image name the same.
Or… add an else section to keep the script going until it detects the full img src and replaces with my full image source.
I hope this makes sense and I look forward to a possible solution.
Thanks, Reece
Upvotes: 1
Views: 887
Reputation: 4021
Typically I'd approach something like this by loading the scraped HTML into PHP's DOMDocument
, finding the image node on there, modifying it, and then writing back out the modified DOMDocument
. For an example of how to use DOMDocument
, see the first answer here: regexp to find image path file in an image tag
Upvotes: 0
Reputation: 2044
Try this
$("#imageId").attr("src", "your new url here");
Give some id
to image & Afterwards you can change its source with jQuery.
Upvotes: 1