Xpath Query to select rows from a table - xpath

I have a web page which has a table with rows of 2 types, Recommended Recyclers and Trade In Prices.
I want to select only those rows from the table which are under Recommended Recyclers category only.
Here is the link of web page:
http://www.sellmymobile.com/phone/orange-spv-m5000/
I need xpath for this selection.

Here a xpath mostly according the explanation form Wrikken.
"//tr[
preceding-sibling::tr[td/#class='section-head']
[1]
[ contains(td, 'Recommended Recyclers')]
][not (td/#class='section-head')]"
With small differences:
Looking for all tr where the first presiding tr with "#class='section-head'" contains an td which contains "Recommended Recyclers". But only tr which has not an td with "#class='section-head'".

Related

XPath to return value only elements containing the text

would like to return value of 'Earnings per share' (i.e. -7.3009, -7.1454, -19.6295, -1.6316)
from "http://www.aastocks.com/en/stocks/analysis/company-fundamental/earnings-summary?symbol=01801"
using below as a example for '-7.3009'
=importxml("http://www.aastocks.com/en/stocks/analysis/company-fundamental/earnings-summary?symbol=01801", "//tr/td[contains(text(),'Earnings')]/td[2]")
However, it returns #N/A.
Can someone help?
this xpath will return your specific data
id("cnhk-list")//tr[td[contains(., "Earnings Per Share")]]/td[starts-with(#class, "cfvalue")]//text()
xpath explanation in english is " you actually needs to select the td where row contains Earnings Per Share which is in table that has some specific ID

xpath for getting table rows with missing cell images

I'm trying to use Xpath to grab in rows of a table containing images and text. Things work fine as long as images are present as on this 3rd table on this page. But when images are missing as in the table as on this page it doesn't work. I need to connect the image with the right row of table data.
Here's the type of xpath_query strings I've been using in google sheets, where A1 contains the url.
=importXML(A1,"//tbody//img/#src")
=importXML(A1,"//tbody//tr")
Thanks for any help.
Shorter alternative with XPath filtering (url in C2, formula in I27) :
=ARRAYFORMULA({{"figura:";IMAGE("https://www.patentati.it/"&IMPORTXML(C2;"//tr//img/#src|//tr[not(.//img)]/td[#class='domanda']"))}\QUERY(IMPORTHTML(C2;"table";1);"select Col2,Col3")})
Output :
Sidenote : I'm based in Europe. Formula for US locales :
=ARRAYFORMULA({{"figura:";IMAGE("https://www.patentati.it/"&IMPORTXML(C2,"//tr//img/#src|//tr[not(.//img)]/td[#class='domanda']"))},QUERY(IMPORTHTML(C2,"table",1),"select Col2,Col3")})
like this:
=ARRAYFORMULA(IMAGE("https://www.patentati.it"&TRIM(SUBSTITUTE(FLATTEN(
SPLIT(QUERY(IFNA(REGEXEXTRACT(QUERY(ARRAY_CONSTRAIN(IMPORTDATA(A1), 500, 1),
"where Col1 matches '.*zoomImage.*|.*rowspan.*'"),
"src=""(.+png)"), "♀♫"),,9^9), "♫")), "♀", ))))
and a whole table:
=ARRAYFORMULA({{"figura"; IMAGE("https://www.patentati.it"&TRIM(SUBSTITUTE(FLATTEN(
SPLIT(QUERY(IFNA(REGEXEXTRACT(QUERY(ARRAY_CONSTRAIN(IMPORTDATA(A1), 500, 1),
"where Col1 matches '.*zoomImage.*|.*rowspan.*'"),
"src=""(.+png)"), "♀♫"),,9^9), "♫")), "♀", )))},
QUERY(IMPORTHTML(A1, "table", 1), "select Col2,Col3", 0)})

Using XPath to find rows where a specific column has value

I'm having trouble using XPath to find a row in a table where a specific column contains a value. The table has 10 columns where 2 of them will show Yes|No but I'm only interested in finding the value in one of the columns (the 4th one). My initial attempt was this:
//table[#id='myTable']/tbody/tr/td[text() = 'Yes']
but it finds it rows from both columns. I thought I could try something like this but it's not a valid expression:
//table[#id='myTable']/tbody/tr/td[4]/text()='Yes'
Any suggestions? Thanks.
You can try this way :
//table[#id='myTable']/tbody/tr[td[4][. = 'Yes']]
The XPath return row (tr) having the forth td child value equals "Yes".

Populating Birt through columns

I have been trying to come up with a birt report to print food tag to no avail. What i want to show on the report is:
foodtag1 | foodtag2 | foodtag3
foodtag4 | foodtag5 | foodtag6
foodtag7 | foodtag8 | foodtag9
Can this be done?
the data is taken from a MySql Query "select dishes.name
from dishes
where find_in_set (dishes.id,(select orders.dishes from orders where orders.id = ))"
** Note: FoodTags 1-9 are all unique name of dishes
** Also note that foodtag 1-9 are representatives of a dish name. FoodTag1 can be "Yang Zhou Fried Rice", it can be "italian Pasta". it can be "Mee Goreng". Data is taken out from a datasource in MYSQL server
The easiest way--
Drag a grid element to your report, set it at 3 columns and 3 rows
In property editor, bind the grid to the data set
Drag a dynamic text element to the first cell in the grid
Then use JavaScript simular to this to filter to the desired text.
if (row["FoodTagColumn"]=='foodtag1'){
row["FoodTagColumn"]
}else null

Play Framework: How to render a table structure from plain SQL table

I would be happy to get a good way to get the "table" structure from a plain SQL table.
In my specific case, I need to render JSON structure used by Google Visualization API "datatable" object:
http://code.google.com/apis/chart/interactive/docs/reference.html#DataTable
However, having an example in HTML would help either.
My "source" is a plain SQL table of "DailySales": its columns are "Day" (date), "Product" and "DailySaleTotal" (daily sale for that product). Please recall that my "model" reflects the 3-column table above.
The table columns should be "products" (suppose we have very small number of such). Each row should represent a specific date, and the row data are the actual sales for that day.
Date Product1 Product2 Product3
01/01/2012 30 50 60
01/02/2012 35 3 15
I was trying to use nested #{list} tags in a template, but unfortunately I failed to find a natural way to provide a template with a "list" to represent the "row data".
Of course, I can build a "helper object" in Java that will build a list of the "sales data" items per date - but this looks very weird to me.
I would be thankful to anyone who can provide an elegant solution.
Max
When you load your model order it by date and product name. Then in your controller build a map with date as index and list of model objects that have the same date as value of the map
Then in your template you have a first list iteration on map keys for the rows and a second list iteration on the list value for the columns.
Something like
[
#{list modelMap.keys, as: 'date'}
[${date},#{list modelMap.get(date), as: 'product'}${product.dailySaleTotal}#{ifnot product_isLast},#{/ifnot}#{/list}]#{ifnot date_isLast},#{/ifnot}
#{/list}
]
you can then adapt your json rendering to the exact structure you want to have. Here it is an array of arrays.
Instead of generating the JSON yourself, like Seb suggested, you can generate it:
private static Result queryToJsonResult(String sql) {
SqlQuery sqlQuery = Ebean.createSqlQuery(sql);
return ok(Json.toJson(sqlQuery.findList()));
}

Resources