I'm trying to get the content of the div with id result_box in google translate using simple_html_dom, but it returns nothing. I tried to return another div's content and it worked perfectly. looks like the problem is just with that div.
result_box is the div that the translation will appear on.
here is my code
$googleSearch="the contente i want to translate";
$googlePage="https://translate.google.com/#en/ar/$googleSearch";
$Chtml = file_get_html($googlePage);
$gt = $Chtml->find('#result_box ',0)->plaintext;
echo '<br>'.$gt.'<br>';
What could be the cause? and how can I solve it?
If this can't be done with simple html dom, is there any alternative ways to do it?
Note that I don't want to use Google translate API
The result_box element does not have any plain text:
<div style="zoom:1" dir="ltr">
<div id="tts_button">
<span id="result_box" class="short_text" lang="en">
<span class="hps">spring</span>
</span>
</div>
I don't know what $Chtml->find('#result_box',0) is doing, but probably you need to iterate to the next <span> and get the text from there
EDIT:
Furthermore, I do not know whether the trailing blank on the Id would probably prevent simple_hmtl_dom from finding anything:
$Chtml->find('#result_box ',0) vs. $Chtml->find('#result_box',0)
Related
I was trying to make this code as below.
PHP code I wrote:
$i = 1;
<div class="sampleNumberIndex">
<p>
<h2> <?php echo $i; ?></h2>
</p>
</div>
Made code that I expected
<div class="sampleNumberIndex">
<p>
<h2> 1 </h2>
</p>
</div>
But php code made this.
<div class="sampleNumberIndex">
<p> </p>
<h2> 1 </h2>
<p> </p>
</div>
I'm using chrome, what did make it like that?
That has nothing to do with PHP. It's just that html doesn't want you to wrap h2-tags in p-tags. You should rather use divs, regardless of what you are trying to accomplish here.
You are probably looking at Inspect Element section which repairs bad HTML codes. Real source codes are available at View page source section. Try Ctrl + U to view source code.
It's not very clear from your question, but I suppose you're seeing the unexpected tags in the browser's DOM inspector. "Show Page Source" should show you the actual raw HTML your browser received.
Edit: what #AliN11 said
HTML infers tags when missing in content. In your case, the HTML browser knows that h2 can't appear in the content of a p element, hence it adds the </p> end-element tag before h2. Then after the h2 element, it encounters the </p> end-element tag, and inserts a <p> start-element tag before it, because none is open at the context position.
The first insertion - that for the </p> end-element tag - is part of the regular parsing rules for HTML; omitting </p> is allowed according to the HTML specification. But the second insertion - that for the <p> start-element tag - is not, and is an effect of HTML recovery (repair) kicking in.
I've explained HTML/SGML tag insertion in detail on the project page of my SGML software and the linked slides of a talk I gave about it last year.
I use mediawiki to take note about the procedure that I follow, the source codes I write in mediawiki are highlighted with the expansion Genshi Syntax HighLight. I want to modify this expansion in mediawiki so it could be created a box above the source code in which it is written the programming language I used. I tried to see expansion sources in my mediawiki but I didn't find the segment in which is "sketch" the <div>. I also saw material about the creation of new expansion in mediawiki to understand how it runs, but I don't understand where the box is created.
I use syntax hightligher like this
some_code
and this is the result in html code generate from mediawiki
<div class="mw-geshi mw-code mw-content-ltr" dir="ltr">
<div class="bash source-bash">
<pre class="de1">
some_code
</pre>
</div>
</div>
I want to prepen the div to first div, like this
<div class='gsh-lang-label'>Language bash</div>
<div class="mw-geshi mw-code mw-content-ltr" dir="ltr">
<div class="bash source-bash">
<pre class="de1">
some_code
</pre>
</div>
</div>
Can you explain me if it is possible to do it and how can I face the problem?
I think ordinary jQuery will solve this problem. Something like:
$(".mw-geshi").each(function(){
$(this).before("<div class='gsh-lang-label'>" +
$(this).children().first().attr("class").split(' ')[0] +
"</div>")
})
Put this in [[MediaWiki:Common.js]], so this script will be run for every user.
This may be a little confusing, so I added an example,
http://searchengineland.com/bing-rises-above-17-search-market-share-as-google-slips-comscore-159746
When clicking the +1 button here, inside the snippet it shows the text and URL from that page.
However, my snippet shows text from the homepage URL, not from the URL I gave it. Why is this and how can I fix it? Sorry if I'm unclear. the code I'm using is below.
<g:plusone size="medium" count="true" href="http://aaaaaa.com/social/comments/'.$row["id"].'">
</g:plusone>
The snippet is generated using the Schema.org markup on your page. To update the text, simply update the itemprop="description" value in your markup for each page within your site. This markup generally looks like:
<body itemscope itemtype="http://schema.org/Product">
<h1 itemprop="name">Shiny Trinket</h1>
<img itemprop="image" src="{image-url}" />
<p itemprop="description">Shiny trinkets are shiny.</p>
</body>
For more information on the snippet, as well as alternatives to Schema markup, see https://developers.google.com/+/web/snippet/.
I want to try and get the latest movie I checked on the IcheckMovies site and display it on my website. I don't know how, I've read about php_get_contents() and then getting an element but the specific element I want is rather deep in the DOM-structure. Its in a div in a div in a list in a ...
So, this is the link I want to get my content from: http://www.icheckmovies.com/profiles/robinwatchesmovies and I want to get the first title of the movie in the list.
Thanks so much in advance!
EDIT:
So using the file_get_contents() method
<?php
$html = file_get_contents('http://www.icheckmovies.com/profiles/robinwatchesmovies/');
echo $html;
?>
I got this html output. Now, I just need to get 'Smashed' so the content of the href link inside the h3 inside a div inside a div inside a list. This is where I don't know how to get it.
...
<div class="span-7">
<h2>Checks</h2>
<ol class="itemList">
<li class="listItem listItemSmall listItemMovie movie">
<div class="listImage listImageCover">
<a class="dvdCoverSmall" title="View detailed information on Smashed (2012)" href="/movies/smashed/"></a>
<div class="coverImage" style="background: url(/var/covers/small/10/1097928.jpg);"></div>
</div>
<h3>
<a title="View detailed information on Smashed (2012)" href="/movies/smashed/">Smashed</a>
</h3>
<span class="info">6 days ago</span>
</li>
<li class="listItem listItemSmall listItemMovie movie">
<li class="listItem listItemSmall listItemMovie movie">
</ol>
<span>
</div>
...
There are some libraries which could help you!
One I've used for the same purpose, a long time ago, is this: http://simplehtmldom.sourceforge.net/
I hope it help you!
follow steps to achieve this
STEP1:-
First get the contents using file_get_contents in a php file
ex: getcontent.php
<?php
echo file_get_contents("http://www.icheckmovies.com/movies/checked/?user=robinwatchesmovies ");
?>
STEP2:-
CALL the above script using ajax call and add the content to a visibility hidden field in the html.
ex:
$('#hidden_div').html(response);
html:-
<html>
<body>
<div id='hidden_div' style='visibility:hidden'>
</div>
</body>
</html>
STEP3:-
now extract the id what ever you want.
What you are asking for is called as web scraping ,I have done this a few months back, the process goes like this,
Make a HttpRequest to the site from which you need the content,check
the php class for it
Use a DOM parse library for handling the downloaded page (it would be in html),simple HTLM DOM would be a good choice
Extract your required information
Here are some tutorials for you,
HTML Parsing and Screen Scraping with the Simple HTML DOM
Library
Beginning web page scraping with php
SO Posts:
HTML Scraping in Php
And best of all Google is your friend just search for "PHP scraping"
Having trouble with jQuery $('#tabs').tabs(); As seen here JSFIDDLE the content that contains an external php file
<li class="files">
Compose Message
</li>
is constantly being shown even when other tabs are hovered upon.I want to eventually change all the anchor tags and link them to other php files. I would like to understand why this fixed content is so and how to eliminate this problem as well as an other tips one may have. I'd greatly appreciate it.
Replace
event:'mouseover'
With
event:'click'
Demo - http://jsfiddle.net/qTXnN/5/
Update
Thats because <a href="msg_inbox.php"> should be <a href="#one">