Simple html dom find strong - dom

<tr>
<td width="70"><strong>Director:</strong></td>
<td><a href="/?&director=Zhangke Jia">Zhangke Jia</td>
</tr>
I try to do this parser but not working
foreach($html->find('strong.Director:') as $titlu) {
echo $titlu->find('a', 0)->plaintext;
}
In need some help please

It is not working because 'Director' is not a class name, It's just a text inside 'td > strong' tag.
These are the ways you can find html dom elements:
Finding HTML elements by id
Finding HTML elements by tag name
Finding HTML elements by class name
Finding HTML elements by HTML object collections
try this:
foreach($html->find('td a') as $titlu) {
echo $titlu->plaintext;
}

Related

Jxbrowser: Get parent element of my element

Is there any way directly get the parent element to find its attributes?
In my situation, I have a
DOMElement img,I have to use functions
img.getparent().getparent().findElement(By.tagName("a")).getAttribute("href"));
and the result is not accuarate since a parent node can find many same type of elements
<td>
<img></img>
<a></a>
<a></a>
<a></a>
<a></a>
</td>
Cast DOMNode to DOMElement and use it's .getAttribute(String attr):
String href = ((DOMElement)(img.getparent())).getAttribute("href");

Removing specific tags that have attributes from html

I want to remove tags from a html file....but only tags with a specific attribute.
For example, I might have the following code:
<span class = 'A'>This is the first sentence.</span><span id = 'B'>This is the second sentence</span>
I want to remove all occurrences of <span id = 'B'> such that the result is as follows
<span class = 'A'>This is the first sentence.</span>This is the second sentence
Any ideas?

Querying a cell in a table in Dart

I would like to query a particular cell of a table in order to change its text or inner HTML.
A sample of the table:
<table id="infotable">
<thead></thead>
<tbody id="tData">
<tr>
<td>SomeCompany1</td>
<td>SomeProduct1</td>
<td>PriceType1</td>
<td id="164">Awaiting data...</td>
</tr>
[...]
The third cell of the first row of the above table is my target which I have identified with the attribute id="164".
In the Dart script, I have attempted two means of querying this cell:
TableCellElement cell = document.query('#164');
and
var cell = query('#164');
Both result in the following error in the Dart editor:
'Error: SyntaxError: DOM Exception 12'
I had this written out when I came across the answer in another SO post, but in the context of jQuery. It turns out the problem was that the id attribute was not allowed to begin with a digit.
Prepending a character to the beginning of the attribute value solved this issue (e.g. the q in id="q164".

Render HTML definition lists in Lift

Another lift beginner question:
I want to render a HTML Definition List in a Lift Snippet like this:
<dl>
<dt>Name</dt>
<dd>Seppl</dd>
<dt>Street</dt>
<dd>abc</dd>
</dl>
The snippet-template looks now like this:
<dl>
<div class="definition">
<dt>Term</dt>
<dd>Description</dd>
</div>
</dl>
The Scala Snippet code:
def render = {
val values=List(("Name", "Seppl"), ("Street", "abc"))
".definition" #> values.map(value =>
("dt" #> value._1) &
("dd" #> value._2))
}
This works, but I want a definition list without div-Tags (I think, this it isn't valid HTML.)
Is this possible with CSS Transformers?
As you don't seem to use CSS I would recommend you to use the following:
Snippet Template code:
<div class="lift:render"/>
Scala Snippet code:
def render = {
val values=List(("Name", "Seppl"), ("Street", "abc"))
values.map(value =>
<dt>{value._1}</dt>
<dd>{value._2}</dd>
)
}
Of course I avoid using CSS selectors so I don't know if it is exactly what you are looking for.
See http://www.assembla.com/spaces/liftweb/wiki/Binding_via_CSS_Selectors
At the end of the page (Iteration) there's an example with unordered list.

The second child of a second child - Jquery

I wanna know how can I get a value of a child of a child. I have this...
<table id="table4">
<tr>
<td>Id:</td>
<td>Name:</td>
</tr>
<tr>
<td>1515</td>
<td>Thiago</td>
</tr>
</table>
In Jquery, I wanna do something like this...
var id = $("#table4:nth-child(2) tr:nth-child(1)").val();
How can I do this work? The first <td> of the second <tr>. I know that I can use "class" and "id" to make it easier, but in this case I can't do that for others reasons.
PS. Sorry about the bad English, I'm a noob in this language.
Thanks.
Like this:
var id = $("#table4 tr:nth-child(2) td:nth-child(1)").text();
You can test it out here. The :nth-child selector applies to the child, for instance the first is saying "a <tr> that is a second child of its parent", rather than your attempted version, which would mean "the second child of this <tr>".
Also, use .text() to get an elements text, rather than .val() which is for input type elements.
This isn't a fully jQuery solution, but just thought I'd point out that you could do this:
var txt = $("#table4")[0].rows[1].cells[0].innerHTML;
Or if there will be any HTML markup you want to avoid, you could do this:
var cell = $("#table4")[0].rows[1].cells[0];
var txt = cell.innerText || cell.textContent;