0

I'm scraping a some sites into a csv which is then used by feeds importer module to create Drupal content.

Some of the content are html chunks containing html+images in them which go into "body"/textarea kind of fields to be displayed.

How do I use feeds tamper or some other method to

  1. Download these embedded images to server and
  2. Rewrite the image paths in the HTML chunks to point to server paths

Possible solution:

  • Rewrite the paths in the html to internal paths registered via "hook_menu". When the path is called, if the image is not there, use "system_retrieve_file" to download the file and serve it .. Example hook_menu() implemented at image_menu. {Thanks Ciss @ drupal-support irc channel} Rewriting would be taken care of by feed_tamper that I have already.

To clarify - I know that if I use image urls with image fields, the images will be downloaded automatically. However I don't know how to download images that are within a HTML chunk.. thanks.

  • At the moment I'm thinking of having another file on the server e.g "localise.php" and rewrite the external urls to point to it, e.g: localise.php?img=example.com/puppy.jpg. The script will check if image is located locally, if not will download and point to it ... seems like a hack / bad way to do it though .. and horrible to maintain .. – a20 Sep 16 '14 at 11:35
1

One possible solution is the feeds_imagegrabber module.

What is does is when the feed is importing it goes to the original web page of the feed item and scrapes the image from the page and imports it into drupal.

Depending on the specifics of your requirements this could be a good easy solution.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.