Scrape <td> into textbox
Moderator: General Moderators
-
kiranindia1986
- Forum Newbie
- Posts: 9
- Joined: Tue Sep 23, 2014 2:01 pm
Scrape <td> into textbox
Hello to All
I am new to PHP. I am trying to scrape website data to my textboxes.
I need "Lähiaadress" and "Asustusüksus" value to textboxes
Here is the link
http://geoportaal.maaamet.ee/url/xgis-k ... 1:006:0812
When i checked the viewsource of the link, we can see its not a well formed table. Any suggestion.
I am new to PHP. I am trying to scrape website data to my textboxes.
I need "Lähiaadress" and "Asustusüksus" value to textboxes
Here is the link
http://geoportaal.maaamet.ee/url/xgis-k ... 1:006:0812
When i checked the viewsource of the link, we can see its not a well formed table. Any suggestion.
Last edited by kiranindia1986 on Tue Sep 23, 2014 2:33 pm, edited 1 time in total.
Re: Scrape <td> into textbox
Link is a 404, for starters.
-
kiranindia1986
- Forum Newbie
- Posts: 9
- Joined: Tue Sep 23, 2014 2:01 pm
Re: Scrape <td> into textbox
It's not a table at all. It's a list and the markup appears to be well-formed. How are you scraping it?
-
kiranindia1986
- Forum Newbie
- Posts: 9
- Joined: Tue Sep 23, 2014 2:01 pm
Re: Scrape <td> into textbox
No idea in PHP, i am vb.net developer, i have scraped in Vb.net, copied all contents to Datagrid, then using regex i removed <li> and copied to textbox.
-
kiranindia1986
- Forum Newbie
- Posts: 9
- Joined: Tue Sep 23, 2014 2:01 pm
Re: Scrape <td> into textbox
I have written following code, but its not retrieving any output.
Code: Select all
function codeAddress1() {
$html = file_get_contents('http://geoportaal.maaamet.ee/url/xgis-ky.php?ky=79401:006:0812');
preg_match_all("(<li.*?>.*?</li>)", $html, $matches);
$days = $matches[1];
echo $days;
}
Re: Scrape <td> into textbox
Code: Select all
$ /usr/bin/php -a
Interactive shell
php > $html = file_get_contents('http://geoportaal.maaamet.ee/url/xgis-ky.php?ky=79401:006:0812');
php > preg_match_all("(<li.*?>.*?</li>)", $html, $matches);
php > print_r($matches);
Array
(
[0] => Array
(
[0] => <li><b>Maakond</b> : Tartu maakond</li>
[1] => <li><b>Omavalitsus</b> : Tartu vald</li>
[2] => <li><b>Asustusüksus</b> : Tila küla</li>
[3] => <li><b>Tunnus</b> : 79401:006:0812</li>
[4] => <li><b>Lähiaadress</b> : Pärna allee 10</li>
[5] => <li><b>Sihtotstarve 1</b> : Elamumaa 100%</li>
[6] => <li><b>Sihtotstarve 2</b> : -</li>
[7] => <li><b>Sihtotstarve 3</b> : -</li>
[8] => <li><b>Pindala</b> : 3230 m²</li>
[9] => <li><b>Haritav maa</b> : -</li>
[10] => <li><b>Rohumaa</b> : -</li>
[11] => <li><b>Metsamaa</b> : -</li>
[12] => <li><b>Õuemaa</b> : 3230 m²</li>
[13] => <li><b>Ehitiste alune maa</b> : -</li>
[14] => <li><b>Muu maa</b> : -</li>
[15] => <li><b>Veealune maa</b> : -</li>
[16] => <li><b>Registreerimise aeg</b> : 06.september 2005. a.</li>
[17] => <li><b>Muudatuse registreerimise aeg</b> : 04.november 2008. a.</li>
[18] => <li><b>Registriosa</b> : korteriomand</li>
[19] => <li><b>Kinnistuspiirkond / jaoskond</b> : Tartu Maakohtu Tartu maakonna kinnistusjaoskond</li>
[20] => <li><b>Mõõdistamise kuupäev</b> : 01.august 2005. a.</li>
[21] => <li><b>Mõõdistaja</b> : OÜ Kinnisvaraekspert Tartu</li>
[22] => <li><b>Mõõdistamisviis</b> : mõõdistatud, L-EST</li>
)
)I don't know if $matches[1] is necessarily what you want, mind you.
-
kiranindia1986
- Forum Newbie
- Posts: 9
- Joined: Tue Sep 23, 2014 2:01 pm
Re: Scrape <td> into textbox
Thanks for your reply
Below code works for me,
Above is for one line. How can we assign $ one to my textbox? That is remaining now.
Below code works for me,
Code: Select all
$html = file_get_contents("http://geoportaal.maaamet.ee/url/xgis-ky.php?ky=79401:006:0812");
preg_match_all('(<li.*?>.*?</li>)', $html, $matches);
$one=$matches[0][0];
Re: Scrape <td> into textbox
Have your function return the value, echo it into the text box. Where are you running into difficulty?
-
kiranindia1986
- Forum Newbie
- Posts: 9
- Joined: Tue Sep 23, 2014 2:01 pm
Re: Scrape <td> into textbox
I added the below code :
I am not getting any output.
Code: Select all
<input id="t49" type="text" class="textbox" value="<?php echo (@$one);?>">Re: Scrape <td> into textbox
Remove the @ as it's only purpose is to suppress errors, which is going to make your life harder. Where is $one defined? Did you assign your function's return value to it?
-
kiranindia1986
- Forum Newbie
- Posts: 9
- Joined: Tue Sep 23, 2014 2:01 pm
Re: Scrape <td> into textbox
Some where i made it work (thanks to Igor Gavryliv).
Now only one part remaining, on button click, i want to copy text box (InputField) value to my URL
Like : http://geoportaal.maaamet.ee/url/xgis-ky.php?ky= + my textbox (InputField) value For Example (79401:006:0812)
Below code is executing on Form load, is that possible to call this php on button click and later javascript code. and value to OutputField textbox.
Now only one part remaining, on button click, i want to copy text box (InputField) value to my URL
Like : http://geoportaal.maaamet.ee/url/xgis-ky.php?ky= + my textbox (InputField) value For Example (79401:006:0812)
Below code is executing on Form load, is that possible to call this php on button click and later javascript code. and value to OutputField textbox.
Code: Select all
<?php
$html = file_get_contents("http://geoportaal.maaamet.ee/url/xgis-ky.php?ky=79401:006:0812");
preg_match_all('(<li.*?>.*?</li>)', $html, $matches);
$one=$matches[0][0];
?>
<script type="text/javascript">
function Assign() {
document.getElementById("OutputField").value = "<?=$one?>";
}
</script>
<input id="OutputField" type="text" style="width:200px"/>
<input id="InputField" type="text" style="width:200px"/>
<input type="button" value="Assign Value" onclick="Assign()"/>Re: Scrape <td> into textbox
That function looks pretty brittle, with the hardcoded ID. What are you trying to do here?
-
kiranindia1986
- Forum Newbie
- Posts: 9
- Joined: Tue Sep 23, 2014 2:01 pm
Re: Scrape <td> into textbox
I would like to pass value to php variable from textbox, then i need to merge that variable with website address:
So it will be something like : "http://geoportaal.maaamet.ee/url/xgis-ky.php?ky=" + inputbox Value.
So it will be something like : "http://geoportaal.maaamet.ee/url/xgis-ky.php?ky=" + inputbox Value.
Re: Scrape <td> into textbox
So you're fetching a value from that site, parsing the HTML to pull out a value, to send right back to that site?