To get image src with phpquery from html page - phpquery

How do i get img src with phpQuery from html page?
Added: I need to get this 'src' to use in parser module for drupal

Here is a short example
$imgsrc = pq('div#foo img.pic')->attr('src');

Related

Django render html with jinja tag in template

I have some little problem. I have site and all content save in database. What could I write in src image tag which save in my database with other HTML text to load images from static folder. For example:<p>Some text</p>
<img src="???">
<p>Another text text</p>. This is the date which is in my database field called 'text'. On main page it load without any problem. But when I go to another page URL variable change from
http: //127.0.0.1:8000/
to
http: //127.0.0.1:8000/page/
and if I wrote in src attribute in database field
'static/img/1.png'
image URL on HTML page become
http: //127.0.0.1:8000/page/static/img/1.png
and image don't load. How could I write or what could I change on my project to fix that?
Add ('/') before static in src of image attribute from database
/static/img/1.png
because we use STATIC_URL = '/static/' in django settings.py

display static html asset in jekyll + github pages

I want to add a link to a static html page (which I have created, not hosted anywhere). I added the html file to my images folder (contains the images which are being rendered in my jekyll blog). Then I make a hyperlink to the html files which I just added in the images folder, like this:
<a href=https://raw.githubusercontent.com/USERNAME/USERNAME.github.io/master/images/time.vs.score.html>View plots here</a>
Where username is my github username. This does not open a new html page, instead I just see the plain text of the html file. How can I add static html files are part of the assets? Thanks!
Thats what raw.githubusercontent.com is made returning raw file.Files are returned with Content-Type:text/plain; and then displayed as text by your browser.
You'd better link to github pages published content at https://USERNAME.github.io/images/time.vs.score.html
I found an easy solution using this tool: https://rawgit.com/
just replace:
<a href=https://raw.githubusercontent.com/USERNAME/USERNAME.github.io/master/images/time.vs.score.html>View plots here</a>
with:
<a href=https://cdn.rawgit.com/USERNAME/USERNAME.github.io/master/images/time.vs.score.html>View plots here</a>

Scalatra link image file outside application

I can't seem to figure out how to display a file in a view that is located outside of the .war file. In the application I am working on I have a folder of images that is volatile at '/path/to/images/'. I am trying to link the file 'myfile.jpg' inside an img tag. In my view (scaml) I have the following code:
-val path = "/path/to/images/" + filename
%img(src = path)
This renders the following img tag
<img src="/path/to/images/myfile.jpg"/>
Scalatra resolves the src url to this invalid url
http://localhost/path/to/images/myfile.jpg
I'm kind of stuck. Can anyone point me in the right direction? I cannot store these images within /src/main/webapp/img
Many thanks,
AH

django-admin and static files

I'm new to django and recently I'm following this tutorial
to write a todo-list app.
In part 2 I should customize the admin's change_list template and add an image into it.
At first I use
<img class='btn' src='static/img/on.png'>
but it turns out to be invalid.
Can anybody figure out what's the problem is? Thanks a lot.
Here is my folder structure
todo-list
todo-app
img
----on.png
----off.png
templates
admin
----change_list.html
todo-list
you can't access the static file( images, css, js ) directly in django
to serve the static files you need to use {{ MEDIA_URL }} or {{STATIC_URL}} for that How do I include image files in Django templates?, and this link
this will helps u :)

Extract URL from document.write()

I have a simple html page that sources a javascript file. The javascript file's only purpose is to write the following...
document.write('<img src="http://www.location.com/image.png">');
Once the information has been written, im needing some javascript to extract the url and the image source and return the url and image locations alone.
Any help is appreciated. Thank you in advance!
Check out this answer which gives shows you how to do it with JQuery or just plain Javascript
UPDATE:
If you have the ability to modify the HTML, then why don't you put in a DOM element that you can hook on to right after where the image will be inserted? Then you can use the following JQuery:
var linkDest = $('#Anchor').prev().attr('href');
var imgSrc = $('#Anchor').prev().children().attr('src');
Which you can see in this JSFiddle example