How do I grab info from source code from other site? - html

Is there a way to grab things out of the source code of another site directly into your site?
For example, let's say than in a site the following source code exists:
<table ...>
<tr>
<td class=...>...</div></td>
</tr>
<tr>
<td class=....><div align="... class=...>"Interesting string that keeps changing"</div></td>
</tr>
</table>
And we want that Interesting string that keeps changing to appear in our website as well.

you could use php
you use
$html = file_get_contents('url to website');
or use a hidden if you want a javascript function, and then just grab the innerhtml

Related

Nested ngRepeat with function call using parent property as parameter displaying wrong lists

I've got a nested ng-repeat that displays a seemingly random list of the possible ones I get.
My HTML is like this:
<table ng-init="getHouses()">
<tr>
<td>Id</td>
<td>Name</td>
</tr>
<tr ng-repeat="h in houses>
<td>{{h.Id}}</td>
<td>{{h.Name}}</td>
<td ng-init="peopleInhHouse(h.Id)">
<span ng-repeat="p in peopleInHouse">p.Name</span>
<br />
</td>
</tr>
I think the problem lies here because I get my lists of people correctly, the problem being that it displays the same list of people for all the different houses and it seems to randomize between everytime I refresh the page.
Your variable peopleInHouse will always reference to the same value. And since you are using a request to get data you can't simply use it directly in the ng-repeat
So just update the ng-init function so it populates the people in the house
The function should look something like
function addPeopleToHouse(house){
request(house.id).then(function(response){
house.People = response.data;
})
}
And update the HTML to
<td ng-init="addPeopleToHouse(h)">
<span ng-repeat="p in h.People">p.Name</span>
<br />
</td>

Turn HTML table into href link tabs

I have browsed through a few answers here on how to turn a HTML table row into a usable link. I could only find people aiming to do this -
<tr>
<td width="15%">Test3</td>
<td><b>Test1</b></td>
<td>Test2</td>
</tr>
Although that does work, it is obviously all separate links and not really what I am looking for. Call me fussy, but I am really trying to aim for something that works similar to the privileges page here.
That is, the entire table row is a link, and no matter where you click, it will redirect. I'm not sure if I would need to use a HTML Table or some kind of List group? Any help would be great!
this solution is really the only way you can do this with HTML properly
<tr>
<td width="15%">Test3</td>
<td><b>Test1</b></td>
<td>Test2</td>
</tr>
Any other solution involves changing the table CSS
I suggest adding the href tag after the like this:
<tr>
<a href="https://google.com">
<td width="15%">Test3</a></td>
<td><b>Test1</b></td>
<td>Test2</td>
</a>
</tr>
This will make all the links clickable with the same URL. However, it wont look 100% like the privileges page since it has no style. Once you add CSS you should be able to achieve exactly what you want.

Advice on how to approach a live feed, containg data from a mysql databse

Hi all as you can probably tell by my two questions yesterday I'm new to wed development. I really need some help on how to approach the next part of my page. So and advice would be great. I'm not really looking for complete/complex code that I can't understand.. I really just want a point in the right direction so I can then work it out / learn myself. CHEERS :D
Okay so basically I have set up a database user accounts and I want to have a rolling feed of new members... . I want to get the feed to go in the main square, how do I code the feed... For the website so far I have used html and php for coding languages. The server is a mysql server. And tips / pointers would be really helpfull :)
my current code:
<?php
//Account validation
session_start();
if(!(isset($_SESSION['login']))){
header("location:welcome.php");
}
?>
<html>
<body>
<table width ="100%" border="1">
<tr>
<td width="25%">
<h1>TOOB</h1>
</td>
<td>
<!all links and stuff>
</td>
</tr>
<tr>
<td>
<h2>Start exploring the TOOB</h2>
</td>
<td width="75%">
</td>
<td>
<form>
<input type="button" value="Logout" onclick="window.location.href='logout.php'">
</form>
</td>
</tr>
</table>
<br>
<table border="1" align="center" width = "60%" height = "500">
<tr>
<td>
<!--FEED GOES HERE-->
</td>
</tr>
</table>
</body>
</html>
You will need to connect to your mysql database and retrieve your user information. Learn more about PDO, there are plenty of tutorials out there, just google 'php pdo'. When you are done with the connection and the retrieval of your data you will have an array you can loop through and display the rows in your page. For the rolling part, you can use javascript and make an ajax get request every few minutes to refresh the information.
Also please consider using css for creating a layout for your page instead of a table.
Let me know if you need more.
If anyone ever comes across this in future months I have found the solution to what I wanted to do on: http://www.phpsimplicity.com/tips.php?id=1
it teahces you how to limit the results of a mysql function to a certain number of rows. it then moves on to how you can for example output the first ten, then the second group of ten and then the third etc..... I just now have to work out how to put that into a form/display typy thing

Looking for an HTML parser to do search/replaces on text nodes

I need to do a lot of various search and replaces within A LOT of static html files. One issue I'm coming up with is I'm getting matches in urls when really all I want to search/replace are text nodes.
So that makes regular expressions more difficult and most likely more error prone since you're parsing html with them now.
What's the easiest way to do search/replaces on only text nodes? I'm talking like you can be up and running within a couple minutes with no Master's required in Python-Java-Ruby-Headless-Phantom-PHP-Node-FluxCapacitor.
Please give advice as though you're speaking to a moron.
I'm on Windows 7.
What I'm looking for is something like the search/replace functionality in Notepad++. You give it a directory to start searching, it searches recursively, hitting every type of file you specify (like .html or .shtml) you tell it what to search for and what to replace it with. It runs and 10 or 15 seconds later you might have edited hundreds of files in one fell swoop. You know, dead simple stuff.
So that's what I want to do, but just searching/replacing within text nodes.
SublimeText 2 has some very powerful text searching features that should empower you to be able to do as you are explaining, so whilst i think i can point you in the right direction - I myself am still learning how to use it - but it does have the "find in files" option which means you can grab the selected word in many different files and replace it - but I havn't found a way to exclude the irrelevant ones that may not need changing. Hopefully someone else will come along and enlighten you.
You may want to add the tag "Sublime text 2" to your original post to broaden the audience
You can use Python and HTQL at http://htql.net. Some examples:
page="<html> <body> <table> <tr><td id='cell1'> test1 </td></tr> <tr> <td id='cell2'> test2 </td> </tr> </table> </body> </html>"
import htql
print(htql.query(page, "<td (id='cell1')>:tx &replace('XXXX') "))
#[("<html> <body> <table> <tr><td id='cell1'>XXXX</td></tr> <tr> <td id='cell2'> test2 </td> </tr> </table> </body> </html>",)]
print(htql.query(page, "<td (id='cell1')>:id &replace('ZZZZ') "))
#[("<html> <body> <table> <tr><td id='ZZZZ'> test1 </td></tr> <tr> <td id='cell2'> test2 </td> </tr> </table> </body> </html>",)]
print(htql.query(page, "<td (id like 'cell%')>:tx &replace('YYYY') "))
#[("<html> <body> <table> <tr><td id='cell1'>YYYY</td></tr> <tr> <td id='cell2'>YYYY</td> </tr> </table> </body> </html>",)]

Jsoup body fragment throws out HTML tags

I have a bit of a dilemma. I need to parse a chunk of HTML through JSoup, that chunk is later passed on to another class that handles the jsoup elements. Unfortunately when I pass a chunk into Jsoup that represents a part of a table, for some odd reason jsoup just throws out all of the html and delivers me nothing, but the text. Here is an example:
<tr>
<td>Declared</td>
<td>Other Supported Languages</td>
<td>/ATP_ETK_89078_1006/atp_etk_89078_1006_p4/nonshared/E-trak_API_Build/obfuscated/vna.dll</td>
<td align="right">1519616</td>
<td align="right"></td>
<td align="right"></td>
<td>COM DEV</td>
<td>Unspecified</td>
<td>License for COM DEV</td>
<td>Component (Dynamic Library)</td>
<td>100%</td>
<td style="text-align: center;"></td>
<td></td>
<td></td>
<td valign="top"></td>
</tr>
<tr>
<td>Declared</td>
<td>Other Supported Languages</td>
<td>/ATP_ETK_89078_1006/atp_etk_89078_1006_p4/nonshared/E-trak_API_Build/obfuscated/vna.dll</td>
<td align="right">1519616</td>
<td align="right"></td>
<td align="right"></td>
<td>COM DEV</td>
<td>Unspecified</td>
<td>License for COM DEV</td>
<td>Component (Dynamic Library)</td>
<td>100%</td>
<td style="text-align: center;"></td>
<td></td>
<td></td>
<td valign="top"></td>
</tr>
This is the fragment and as you can see it just represents two rows from a table.
However the Jsoup Doc produces the following:
<html>
<head></head>
<body>
Declared Other Supported Languages /ATP_ETK_89078_1006/atp_etk_89078_1006_p4/nonshared/E-trak_API_Build/obfuscated/vna.dll 1519616 COM DEV Unspecified License for COM DEV Component (Dynamic Library) 100%
Declared Other Supported Languages /ATP_ETK_89078_1006/atp_etk_89078_1006_p4/nonshared/E-trak_API_Build/obfuscated/vna.dll 1519616 COM DEV Unspecified License for COM DEV Component (Dynamic Library) 100%
</body>
</html>
Now if the original headers of the table were there including the table open/close headers it seems to work, but that defeats the entire purpose of this fragment parsing as the HTML docs can get quite huge.
ANY HELP would be greatly appreciated.
Tested with JSoup 1.7.1 --> same problem.
I guess, the only way is to wrap your fragment into a table-tag.
String html = ... // your html
Document doc = Jsoup.parse(html);
// doesn't work as you said
String html = ... // your html
Document doc = Jsoup.parse("<table>" + html + "</table>");
// works
Don't know how you use Jsoup in your case, but maybe you can do somethink like this:
public String doSomethingWithFragment(String html)
{
Document doc = Jsoup.parse("<table>" + html + "</table>");
Elements fragment = doc.select("tbody > *");
// Do something with 'fragment' here ...
}
In this example fragment contains exactly the HTML as you posted above and you can do further things with it.
I know its a realy strange workaround - adding things and remove it in the next step. But however ... it works (i hope) :-) ...