Due to Same Origin Policy restrictions, you can not access contents of iframe if it is running a page from another domain. There are solutions to same domain policy like
- Opening a page via a proxy
Check out Tomodo. It is just to give you a hint how they used proxy to bypass same origin policy constraint and access iframe content. So the implementation idea goes like this
- Create a proxy and host it at
a.com/proxy
- Host your main page at
a.com/index.html
- Now, request your proxy to give you content of iframe_url something like this
a.com/proxy?url=iframe_url.com
Please note this is not a trivial task and you may have to handle a lot of cases at your proxy like handling relative URLs, cookie reading by iframe_url etc etc. So go for it only if you need it desperately.
Another solution might be this:
If you want to download some images for a particular domain, just ask your server side code to it for you. Your backend code will fetch the html of page and use some HTML parser like
- BeautifulSoup for python (Documentation Link)
- Jsoup for Java (Documentation Link)
to parse img tags and extract the source and fetch the images and download them.
PS: Just for some good information, please read Ways to circumvent same origin policy