How to read image ALT tag using Simple HTML Dom Parser? - html-parsing

I would like to fetch the information contained in the ALT attribute of the image on the website using Simple HTML Dom Parser. Here's the code:
I need to fetch only "pasazbiurowy.pl" as a plaintext.

<img src="//image.ceneostatic.pl/data/shops/19572/logo.jpg" alt="pasazbiurowy.pl" data-original="//image.ceneostatic.pl/data/shops/19572/logo.jpg" class=" lazyloaded">

Related

Making image url link only with plain text using auto_html Gem

I put the following text and got an unexpected result using the bundled image filter (AutoHtml::Image).
<img src="http://hoge/image.png">
That filter translated it into the followging code.
<img src=""
<a href="http://hoge/image.png">
<img src="http://hoge/image.jpg">
</a>
"">
I just wanted to transralte only with plain text not with html tag.
How can I solve that problem?
The auto_html gem is supposed to transform plain text input, not HTML input into HTML. The AutoHtml::Image filter simply finds all URLs, such as "http://hoge/image.png" and transforms them into an HTML image tag: <img src="http://hoge/image.png"> (see the last example usage in the gem's README). There is no point in applying this filter to a text that already contains HTML tags.
So in your case, perhaps you simply should not use the image filter at all?

HtmlPurifier - Codeblock

I was looking in HtmlPurifier documentation, but I can't see nothing about that.
Let's say I have
<div class="codebox">
All html tags here - Even <div class="codebox">another code box</div>
</div>
I want to parse the content of the first <div class="codebox"> so it can be readable as plaintext.
Can htmlpurifier do that ?
Out of the box HTMLPurifier can't do that and there is no config setting, that I know of, that can convert only the first <div> tag to plain text without converting the entire document. And even for converting the entire document to text the HTMLPurifier is neither needed nor recommended.
You can extend functionality of HTMLPurifier but unless you are an expert coder, I wouldn't recommend doing that.
However if you want to convert a part of the HTML document to text then break it into parts and run the part which you want to convert to text through
strip_tags()
PHP Manual page on strip_tags
You could convert all the div tags in your document to plain text with this configuration directive:
$config->set(HTML.ForbiddenElements, 'div'); //This will black list 'div' tag
And if you absolutely insist on converting your entire document to text using HTMLPurifier then here is the config directive that will do that.
$config->set('HTML.Allowed', ''); //This will white list NO tags ''

iMacros get the ID of a div, not the content

I am trying to learn iMacros (and avoid jscript or vbscript IF possible). I was reading any resource i could find since yesterday and the imacros reference does not have any helpful example of what i need.
All the methods I tried, will extract either the TXT or the HTM content of an element. My problem is that i have a div like this
<div class="cust_div" id="Customer_45621">
...content in here...
</div>
And the part i need to extract is 45621 which is the only dynamic part of the id attribute.
For example, between 3 customers, it could be
Customer_45621
Customer_35123
Customer_85663
All I need is the number. Thanks.
The solution is
TAG POS=1 TYPE=DIV ATTR=cust_div EXTRACT=HTM
Then you have to use EVAL and use in it JS scripting to extract the id. That is the only way. You can't cut the HTML code without JS, but you can use JS in iMacros with EVAL.

Mercury Editor save images

I used Mercury Editor for my Rails 3 website, but i have a litte problem with the uploaded images.
I have a image tag with data-mercury="image":
<img id="page_image" data-mercury="image" >
Then I set Mercury to send the data via a form to my controller. What I want to do is to store the image's url in the database.
How do I get the data sent by Mercury Editor ?
Normally when I have a div with data-mercury="full", I get the content in my controller like that:
params[:content][:page_content][:value]
Thanks for your help.
as I check the mercury demo , it saved the pictures url. So ,probably you can parse the content and capture the image url by using regular expression. Maybe you can use nokogiri as well to parse the html.
Rails Cast Source
Official Mercury docmentation
I resoved the problem with the following code:
#body
<img id="mercury_image" data-mercury="image" src="">
<div id="article_image" data-mercury="full"></div>
#jQuery
$(function() {
$('#article_image').hide() ;
$("#mercury_image").load(function(){
$('#article_image').html($('#mercury_image').attr('src'));
});
});

Drupal 7: how to get image url to display image

In Drupal 7, I'm using the feeds module to pull in a bunch of books
That's all working perfectly. I am not setting up some views.
the feed pulls in an image url to on o my field like this [http://img.techbook.com/techwords/content/bk/blak/003834/full_image.jpg
but of course I need
<img src="http://img.techbook.com/techwords/content/bk/blak/003834/full_image.jpg" />
to display the image on the page
What is the best method of altering this fields' text, or is there a method so I can automatically format correctly. There are hundres of these, so manually do it is not an option
You can either use Feeds Tamper, which let's you manipulate the incoming feed data before it comes in (ie. wrap the url with img tags): http://drupal.org/project/feeds_tamper
OR
You can simply import the URLs into a field, and then render the URL with a template file that has the img tag wrapped around the field.
Like so: in node--content-type-name-here.tpl.php
<img src="<?php print render($content['field_url']); ?>" />
I would recommend the latter and only use Feeds Tamper for more serious manipulations.

Resources