Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Pomos okolo asp.net windows form application

[es] :: .NET :: ASP.NET :: Pomos okolo asp.net windows form application

[ Pregleda: 2311 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Viktor84
Viktor Pesevski
student
Kumanovo

Član broj: 286332
Poruke: 34
*.cabletel.com.mk.



+19 Profil

icon Pomos okolo asp.net windows form application23.06.2012. u 14:00 - pre 143 meseci
Zdravo,
ja sam student na IT faklutetu ali jos nisam dovoljno razvio svoje vestine da mogu da pronagjem sve sto mi treba oko nekih moi sitnih proekta.
Ovako,dok studiram poceo sam da radim za marketin sluzbu,tamo sam dobio rabotu da pravim neke reklame u HTML formatu.
E sada,ja sam napravio prostu web aplikaciju u asp.net c# u koje ja unosim 5 slike sa web sajtom,opis oko apartmana,komentar ,cena,broj sobe,link koji je strana,kao i koji dodatci ima taj apartman.
Sada bi zeleo da mogu da napravim program koji bi uzimao sam podatce sa tom web sajtom (evo ga : http://www.airbnb.com/rooms/269080),na primer da unesem samo text polje na koje mogu da upisem web stranicu i od nje program sam da napravi .txt fajl na koji bi imalo podatke koje mi treba ,ne celi sorce file sa web sajta.

Evo kako bi trebalo da mi bude .txt fajl sa HTML kodom unutra :


<table width="100%"><tbody><tr><td align="left"><div><table><tbody><tr><td valign="top" width="475"><div><a
href="http://airbandb.com/rooms/269080?af=654702&c=direct_link"rel="nofollow"><img alt="Garden Flat-Parking available " height="330"
src="http://a2.muscache.com/pictures/2690374/large.jpg" width="445"></a></div><br><table><tbody><tr><td width="108"><a href="http://airbandb.com/rooms/269080?af=654702&c=direct_link" rel="nofollow"><img alt="Large" height="144"
src="http://a1.muscache.com/pictures/2690346/large.jpg" width="216"></a></td><td width="108"><a href="http://airbandb.com/rooms/269080?af=654702&c=direct_link" rel="nofollow"><img alt="Large" height="144"
src="http://a2.muscache.com/pictures/2690339/large.jpg" width="216"></a></td></tr><tr><td width="108"><a href="http://airbandb.com/rooms/269080?af=654702&c=direct_link" rel="nofollow"><img alt="Large" height="144"
src="http://a0.muscache.com/pictures/2690369/large.jpg" width="216"></a></td><td width="108"><a href="http://airbandb.com/rooms/269080?af=654702&c=direct_link" rel="nofollow"><img alt="Large" height="144"
src="http://a0.muscache.com/pictures/2690369/large.jpg" width="216"></a></td></tr></tbody></table></td><td valign="top"><div><b><font size="6">
Apartment - Entire home/apt
</font></b></div><br><table><tbody><tr><td width="135" valign="top"><div><b><font size="6">
155 / night
</font></b>
</div><div>per night </div></td><td width="200" valign="top"><font size="2"><ul><div>Includes:</div>
<li>Pets Allowed</li><li>TV</li><li>Cable TV</li><li>Internet</li><li>Wireless Internet</li><li>Air Conditioning</li><li>Heating</li><li>Elevator in Building</li><li>Handicap Accessible </li><li>Pool</li><li>Kitchen </li><li>Parking Included</li><li>Gym</li><li>Hot Tub</li><li>Family/Kid Friendly</li><li>Washer </li><li>Dryer</li> </ul>
</font></td><td width="125" valign="top"></td><td width="115" valign="top"></td></tr></tbody></table>
<div><b><font size="5">Description</font></b></div><div>
<font size="2">
Ultra chic luxury and spacious one bedroom apartment, right next to Renaissance Hollywood Hotel at community situated on one of the most renowned and historic city blocks in Los Angeles. Located on the Walk of Fame, the apartment building is brand new.
This 1 bedroom ultra chic vacation home is located on the top floor, getting sunlight throughout the day, and has a downtown skyline and Hollywood Hills view.
Dining area for 6 people, comfortable sofa, work desk, breakfast bar.
42 inch HDTV with Time Warner Cable, Unlimited Nationwide Calls, Fast Broadband Wireless Internet.
Coffee machine, toaster and other kitchen amenities to make yourself comfortable.
Queen size bed and walk in closet in bedroom.
Gym with high quality and stainless steel equipments, branded cardio and weight equipment, jacuzzi, heated pool on site.
Business center and conference rooms available.
24 hour security. Concierge during day time.
<a href="http://airbandb.com/rooms/269080?af=654702&c=direct_link"rel="nofollow">Read full description</a></font></div><br><div><b>
<font size="5">Recent review</font></b></div><div>
<font size="2">
Very nice apartment. Clean and well maintained. A lot of amenities are provided. Meet and greet was friendly and there before us. Having parking was very convenient. Walking distance to a lot of attractions and short drive to basically everything else. Really enjoyed our stay here.</font>
<font size="2">
New York, NY
<br /><br /><br />
<big><a href="http://airbandb.com/rooms/269080?af=654702&c=direct_link"rel="nofollow">Click here to book</a></big>
</font></div></td></tr>
</tbody></table></div></td></tr></tbody></table>

Zamoli bi vas ako moze neko da me uputi sta tacno treba da uradim .Pokusao sam sa StreamReader i StreamWriter ali nemogu nikako da podesim program da mi sam izbira koji stvari mi trebaju ,nego samo program mi uzima ceo sorce file i ubaci u .txt dokument.Ako treba mogu i da ubacim i cod sa programa koji koristim sad koj hocu da smenim sa necim laksijem.
Pozdrav i hvala unapred.
 
Odgovor na temu

Dejan Carić
Oslo, Norway

Član broj: 230976
Poruke: 232
*.dynamic.isp.telekom.rs.

Sajt: www.dcaric.com


+26 Profil

icon Re: Pomos okolo asp.net windows form application24.06.2012. u 00:16 - pre 143 meseci
Ne razumem baš šta hoćeš da postigneš sa tim .txt fajlovima i HTML-om koji si postavio, ali mislim da ti ovo može pomoći :)
Ono što tebi treba je HtmlAgilityPack. Možeš da ga skineš direktno sa sajta ili da ga instaliraš kao NuGet paket.

Evo kako da skineš opis sobe sa pomenutog linka...
Kada otvoriš http://www.airbnb.com/rooms/269080 u Firebug-u ili nekom drugom alatu, videćeš da tekst koji ti treba se nalazi u DIV-u koji ima ID description_text_wrapper.



Source code za konzolnu aplikaciju koja čita description:

Code:

using System;
using System.Net;
using HtmlAgilityPack;

namespace ConsoleApplication1
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            string description = GetDescription("http://www.airbnb.com/rooms/269080");
            Console.WriteLine(description);
        }

        private static string GetDescription(string url)
        {
            using (var webClient = new WebClient())
            {
                // Procitaj source code stranice
                string content = webClient.DownloadString(url);

                // Ucitaj source code u HtmlDocument s kojim mozes lako da parsiras dobijeni HTML
                var htmlDocument = new HtmlDocument();
                htmlDocument.LoadHtml(content);

                // pronadji DIV koji ima ID 'description_text_wrapper'
                var descriptionNode = htmlDocument.DocumentNode.SelectSingleNode("//div[@id='description_text_wrapper']");

                // Procatiaj tekst koji se nalazi unutar tog DIV-a i ukloni sve HTML tagove (<b>, <p>, itd.)
                // Ukoliko ne postoji DIV sa tim ID-em, vrati prazan string.
                var description = descriptionNode == null ? string.Empty : descriptionNode.InnerText.Trim();
                return description;
            }
        }
    }
}

Prikačeni fajlovi
 
Odgovor na temu

Viktor84
Viktor Pesevski
student
Kumanovo

Član broj: 286332
Poruke: 34
*.cabletel.com.mk.



+19 Profil

icon Re: Pomos okolo asp.net windows form application24.06.2012. u 01:38 - pre 143 meseci
Hvala mnogo snaci cu se nadam se dalje,ako nesta mi ustreba pisem.
pozz i jos jednom hvala.
 
Odgovor na temu

Viktor84
Viktor Pesevski
student
Kumanovo

Član broj: 286332
Poruke: 34
*.cabletel.com.mk.



+19 Profil

icon Re: Pomos okolo asp.net windows form application24.06.2012. u 19:53 - pre 143 meseci
Ako moze jos da mi pokazes kako da stavim jedan review od ove stranice pr : http://www.airbnb.com/rooms/324834.Hteo bi da izvadim samo ovo :
Very pleasant stay. Chris was fantastic and easy to work with. Even let us come a day early. The unit was newly remodeled and neatly furnished. Definately on my list of "will be back again". Thanks Chris

Ja kad sredim kod izvade se sve komentari sto ne mi trebaju ,bolje bi bilo da izvadim samo prvi.

Jos jedna stvar je kako bi mogao da izvadim destinacije od 5 slike ? ono sta ide u <img src="......">

Ako mozes samo jos ovih dva koda da mi pokazes,molim te .
 
Odgovor na temu

Dejan Carić
Oslo, Norway

Član broj: 230976
Poruke: 232
82.117.199.*

Sajt: www.dcaric.com


+26 Profil

icon Re: Pomos okolo asp.net windows form application25.06.2012. u 08:52 - pre 143 meseci
Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using HtmlAgilityPack;

namespace ConsoleApplication1
{
    internal class Program
    {
        public class Room
        {
            public string Description { get; set; }

            public List<string> Reviews { get; set; }
            public bool HasReviews
            {
                get { return Reviews != null && Reviews.Count > 0; }
            }

            public List<string> Images { get; set; }
            public bool HasImages
            {
                get { return Images != null && Images.Count > 0; }
            }
        }

        public static void Main(string[] args)
        {
            var room = GetRoom("http://www.airbnb.com/rooms/324834");

            Console.WriteLine("DESCRIPTION");
            Console.WriteLine("===========");
            Console.WriteLine(room.Description);
            Console.WriteLine();

            // prva slika
            if (room.HasImages)
            {
                Console.WriteLine("IMAGE");
                Console.WriteLine("===========");
                Console.WriteLine(room.Images[0]);
                Console.WriteLine();
            }

            // prvi opis
            if (room.HasReviews)
            {
                Console.WriteLine("REVIEW");
                Console.WriteLine("===========");
                Console.WriteLine(room.Reviews[0]);
                Console.WriteLine();
            }
        }

        private static Room GetRoom(string url)
        {
            using (var webClient = new WebClient())
            {
                var room = new Room();

                // Procitaj source code stranice
                string content = webClient.DownloadString(url);

                // Ucitaj source code u HtmlDocument s kojim mozes lako da parsiras dobijeni HTML
                var htmlDocument = new HtmlDocument();
                htmlDocument.LoadHtml(content);

                room.Description = GetDescription(htmlDocument);
                room.Reviews = GetReviews(htmlDocument);
                room.Images = GetImages(htmlDocument);

                return room;
            }
        }

        private static string GetDescription(HtmlDocument htmlDocument)
        {
            // pronadji DIV koji ima ID 'description_text_wrapper'
            var descriptionNode = htmlDocument.DocumentNode.SelectSingleNode("//div[@id='description_text_wrapper']");

            // Procatiaj tekst koji se nalazi unutar tog DIV-a i ukloni sve HTML tagove (<b>, <p>, itd.)
            // Ukoliko ne postoji DIV sa tim ID-em, vrati prazan string.
            string description = descriptionNode == null ? string.Empty : descriptionNode.InnerText.Trim();

            return description;
        }

        private static List<string> GetReviews(HtmlDocument htmlDocument)
        {
            // Pronadji sve P tagove koji imaju klasu 'message',
            // a koji se nalaze unutar LI tag-a koji ima klasu 'reviews-list-item clearfix '
            var reviewNodes = htmlDocument.DocumentNode
                .SelectNodes("//li[@class='reviews-list-item clearfix ']//p[@class='message']");

            // Ako ne postoje tagovi, vrati praznu listu
            if (reviewNodes == null)
                return null;

            // Ako postoje tagovi, uzmi tekst i ukloni sve HTML tagove (<b>, <p>, itd.)
            var reviews = new List<string>(reviewNodes.Count);
            reviews.AddRange(reviewNodes.Select(reviewNode => reviewNode.InnerText.Trim()));

            return reviews;
        }

        private static List<string> GetImages(HtmlDocument htmlDocument)
        {
            // Pronadji sve A tagove koji se nalaze unutar DIV-a koji ima klasu 'galleria_container'
            var imageNodes = htmlDocument.DocumentNode.SelectNodes("//div[@id='galleria_container']//a");

            // Ako ne postoje tagovi, vrati praznu listu
            if (imageNodes == null)
                return null;

            // Ako postoje tagovi, uzmi vrednost 'href' atributa
            var images = new List<string>(imageNodes.Count);
            images.AddRange(imageNodes.Select(imageNode => imageNode.GetAttributeValue("href", string.Empty)));

            return images;
        }
    }
}


[Ovu poruku je menjao Dejan Carić dana 25.06.2012. u 10:03 GMT+1]
 
Odgovor na temu

Viktor84
Viktor Pesevski
student
Kumanovo

Član broj: 286332
Poruke: 34
*.cabletel.com.mk.



+19 Profil

icon Re: Pomos okolo asp.net windows form application25.06.2012. u 10:52 - pre 143 meseci
Hvala opet, sada sam sredio progrm .
 
Odgovor na temu

[es] :: .NET :: ASP.NET :: Pomos okolo asp.net windows form application

[ Pregleda: 2311 | Odgovora: 5 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.