public bool MoveNext() { while (_xmlEnum.MoveNext()) { XXElement xeHeader = _xmlEnum.Current; _header = new Gesat_HeaderCompany(); _header.sourceUrl = _url; _header.loadFromWebDate = DateTime.Now; //<span class="NOM"><a title="ESAT BETTY LAUNAY-MOULIN VERT" href="/Gesat/Hauts-de-Seine,92/Bois-Colombes,35494/esat-betty-launay-moulin-vert-competences-et-handicap-92,e1837/">ESAT BETTY LAUNAY-MOULIN VERT</a></span> //_header.companyName = xeHeader.ExplicitXPathValue(".//span[@class='NOM']//a//text()"); XXElement xe = xeHeader.XPathElement(".//span[@class='NOM']//a"); if (xe != null) { _header.url = GetUrl(xe.ExplicitXPathValue("@href")); //_header.name = xe.ExplicitXPathValue(".//text()", _trimFunc1); _header.name = _trimFunc1(xe.ExplicitXPathValue(".//text()")); } //<span class="VILLE">E.S.A.T.<br />Bois-Colombes (92)</span> xe = xeHeader.XPathElement(".//span[@class='VILLE']"); if (xe != null) { //IEnumerator<string> texts = xe.DescendantTextList().GetEnumerator(); IEnumerator <string> texts = xe.DescendantTexts().GetEnumerator(); if (texts.MoveNext()) { _header.type = texts.Current.Trim(); } else { Trace.CurrentTrace.WriteLine("error companyType not found"); } if (texts.MoveNext()) { _header.location = texts.Current.Trim(); } else { Trace.CurrentTrace.WriteLine("error companyLocation not found"); } } // <span class="TELEPHONE">01 47 86 11 48</span> //_header.phone = xeHeader.ExplicitXPathValue(".//span[@class='TELEPHONE']//text()", _trimFunc1); _header.phone = _trimFunc1(xeHeader.ExplicitXPathValue(".//span[@class='TELEPHONE']//text()")); //<img info_bulle="Signataire de la charte Ethique et Valeurs" border="0" alt="/images/bullesGesat/pictoCharte.png" src="/images/bullesGesat/pictoCharte.png" style=" border: 0;" /> //<img info_bulle="Lauréat des trophées HandiResponsables 2013" border="0" alt="/images/bullesGesat/LAURIERS-OR-2013.png" src="/images/bullesGesat/LAURIERS-OR-2013.png" style=" border: 0;" /> //_header.infos = xeHeader.XPathValues(".//img/@info_bulle", _trimFunc1); _header.infos = xeHeader.XPathValues(".//img/@info_bulle").Select(_trimFunc1).ToArray(); //_header.SetInfo(xeHeader.XPathValues(".//img/@info_bulle")); return(true); } return(false); }
protected override void SetXml(XElement xelement) { XXElement xeSource = new XXElement(xelement); _data = new Gesat_HeaderPage(); // <div class="PAGENAVIGLIST"> // <a href="/Gesat/EtablissementList-10-10.html" title="page suivante">></a> _data.urlNextPage = GetUrl(xeSource.XPathValue("//div[@class='PAGENAVIGLIST']//a[@title='page suivante']/@href")); // <div class="ETABLISSEMENT STAR-1 ODD"> <div class="ETABLISSEMENT STAR-0 ODD"> <div class="ETABLISSEMENT STAR-1 EVEN"> IEnumerable <XXElement> xeHeaders = xeSource.XPathElements("//div[starts-with(@class, 'ETABLISSEMENT STAR-')]"); List <Gesat_HeaderCompany> headers = new List <Gesat_HeaderCompany>(); foreach (XXElement xeHeader in xeHeaders) { Gesat_HeaderCompany header = new Gesat_HeaderCompany(); header.sourceUrl = _url; header.loadFromWebDate = DateTime.Now; //<span class="NOM"><a title="ESAT BETTY LAUNAY-MOULIN VERT" href="/Gesat/Hauts-de-Seine,92/Bois-Colombes,35494/esat-betty-launay-moulin-vert-competences-et-handicap-92,e1837/">ESAT BETTY LAUNAY-MOULIN VERT</a></span> //_header.companyName = xeHeader.ExplicitXPathValue(".//span[@class='NOM']//a//text()"); XXElement xe = xeHeader.XPathElement(".//span[@class='NOM']//a"); if (xe != null) { header.url = GetUrl(xe.ExplicitXPathValue("@href")); //header.name = xe.ExplicitXPathValue(".//text()", _trimFunc1); header.name = _trimFunc1(xe.ExplicitXPathValue(".//text()")); } //<span class="VILLE">E.S.A.T.<br />Bois-Colombes (92)</span> xe = xeHeader.XPathElement(".//span[@class='VILLE']"); if (xe != null) { //IEnumerator<string> texts = xe.DescendantTextList().GetEnumerator(); IEnumerator <string> texts = xe.DescendantTexts().GetEnumerator(); if (texts.MoveNext()) { header.type = texts.Current.Trim(); } else { Trace.CurrentTrace.WriteLine("error companyType not found"); } if (texts.MoveNext()) { header.location = texts.Current.Trim(); } else { Trace.CurrentTrace.WriteLine("error companyLocation not found"); } } // <span class="TELEPHONE">01 47 86 11 48</span> //header.phone = xeHeader.ExplicitXPathValue(".//span[@class='TELEPHONE']//text()", _trimFunc1); header.phone = _trimFunc1(xeHeader.ExplicitXPathValue(".//span[@class='TELEPHONE']//text()")); //<img info_bulle="Signataire de la charte Ethique et Valeurs" border="0" alt="/images/bullesGesat/pictoCharte.png" src="/images/bullesGesat/pictoCharte.png" style=" border: 0;" /> //<img info_bulle="Lauréat des trophées HandiResponsables 2013" border="0" alt="/images/bullesGesat/LAURIERS-OR-2013.png" src="/images/bullesGesat/LAURIERS-OR-2013.png" style=" border: 0;" /> //header.infos = xeHeader.XPathValues(".//img/@info_bulle", _trimFunc1); header.infos = xeHeader.XPathValues(".//img/@info_bulle").Select(_trimFunc1).ToArray(); //_header.SetInfo(xeHeader.XPathValues(".//img/@info_bulle")); headers.Add(header); } _data.headerCompanies = headers.ToArray(); }
protected override Unea_HeaderCompany[] GetData() { XXElement xeSource = new XXElement(GetXmlDocument().Root); string url = Url; // <div class="ctn_result"> IEnumerable <XXElement> xeHeaders = xeSource.XPathElements("//div[@class = 'ctn_result']"); List <Unea_HeaderCompany> headers = new List <Unea_HeaderCompany>(); foreach (XXElement xeHeader in xeHeaders) { Unea_HeaderCompany header = new Unea_HeaderCompany(); header.sourceUrl = url; header.loadFromWebDate = DateTime.Now; // <div class="ctn_result-header"> XXElement xe = xeHeader.XPathElement(".//div[@class='ctn_result-header']"); // <div class="lien"><a href="http://www.unea.fr/union-nationale-entreprises-adaptees/annuaire-unea/71/4583/ACCAA TAKTIM.htm" target="_blank"><strong>></strong> Voir la fiche détaillée</a></div> header.urlDetail2 = zurl.GetUrl(url, xe.ExplicitXPathValue(".//div[@class = 'lien']//a/@href")); // <iframe src="detail.asp?id=4583" width="420" height="800" frameborder="0" scrolling="auto" marginheight="0" marginwidth="0"></iframe> header.urlDetail1 = zurl.GetUrl(url, xe.ExplicitXPathValue(".//iframe/@src")); // <h4><a href="http://www.unea.fr/union-nationale-entreprises-adaptees/annuaire-unea/71/4583/ACCAA TAKTIM.htm" target="_blank"> </a><span>|</span> ACCAA TAKTIM</h4> //header.name = xe.DescendantTextList(func: __trimFunc2).LastOrDefault(); header.name = xe.DescendantTexts().Select(__trimFunc2).LastOrDefault(); // <div class="ctn_result-content clearfix"> // ... // <p> // <strong>Activités:</strong> TRAVAUX PAYSAGERS<br>PROPRETE<br>PRESTATION DE SERVICES<br>SOUS TRAITANCE INDUSTRIELLE<br>MECANIQUE<br>AUTOMOBILE<br>METALLURGIE<br /> // <strong>Région - Département:</strong> Alsace - HAUT RHIN (68)<br /> // <strong>Téléphone:</strong> 0389570210 // <strong>Fax:</strong> 0389571761 // <strong>Adresse e-mail:</strong> // <a href="mailto:[email protected]">[email protected]</a> // </p> // </div> Unea_TextType textType = Unea_TextType.unknow; //foreach (string s in xeHeader.DescendantTextList(".//div[@class = 'ctn_result-content clearfix']", func: __trimFunc2)) foreach (string s in xeHeader.XPathElements(".//div[@class = 'ctn_result-content clearfix']").DescendantTexts().Select(__trimFunc2)) { if (s.Equals("Activités", StringComparison.InvariantCultureIgnoreCase)) { textType = Unea_TextType.activity; } else if (s.Equals("Région - Département", StringComparison.InvariantCultureIgnoreCase)) { textType = Unea_TextType.location; } else if (s.Equals("Téléphone", StringComparison.InvariantCultureIgnoreCase)) { textType = Unea_TextType.phone; } else if (s.Equals("Fax", StringComparison.InvariantCultureIgnoreCase)) { textType = Unea_TextType.fax; } else if (s.Equals("Adresse e-mail", StringComparison.InvariantCultureIgnoreCase)) { textType = Unea_TextType.email; } else { switch (textType) { case Unea_TextType.activity: if (!header.activities.ContainsKey(s)) { header.activities.Add(s, null); } break; case Unea_TextType.location: header.location = s; textType = Unea_TextType.unknow; break; case Unea_TextType.phone: header.phone = s; textType = Unea_TextType.unknow; break; case Unea_TextType.fax: header.fax = s; textType = Unea_TextType.unknow; break; case Unea_TextType.email: header.email = s; textType = Unea_TextType.unknow; break; default: header.unknowInfos.Add(s); break; } } } headers.Add(header); } return(headers.ToArray()); }
// header get data, from WebHeaderDetailMongoManagerBase_v2<THeaderData, TDetailData> protected override IEnumDataPages <Gesat_Header_v2> GetHeaderPageData(HttpResult <string> httpResult) { XXElement xeSource = httpResult.zGetXDocument().zXXElement(); string url = httpResult.Http.HttpRequest.Url; Gesat_HeaderDataPages data = new Gesat_HeaderDataPages(); data.SourceUrl = url; data.LoadFromWebDate = httpResult.Http.RequestTime; data.Id = GetPageKey(httpResult.Http.HttpRequest); // <div class="PAGENAVIGLIST"> // <a href="/Gesat/EtablissementList-10-10.html" title="page suivante">></a> data.UrlNextPage = zurl.GetUrl(url, xeSource.XPathValue("//div[@class='PAGENAVIGLIST']//a[@title='page suivante']/@href")); // <div class="ETABLISSEMENT STAR-1 ODD"> <div class="ETABLISSEMENT STAR-0 ODD"> <div class="ETABLISSEMENT STAR-1 EVEN"> IEnumerable <XXElement> xeHeaders = xeSource.XPathElements("//div[starts-with(@class, 'ETABLISSEMENT STAR-')]"); List <Gesat_Header_v2> headers = new List <Gesat_Header_v2>(); foreach (XXElement xeHeader in xeHeaders) { Gesat_Header_v2 header = new Gesat_Header_v2(); header.SourceUrl = url; header.LoadFromWebDate = DateTime.Now; //<span class="NOM"><a title="ESAT BETTY LAUNAY-MOULIN VERT" href="/Gesat/Hauts-de-Seine,92/Bois-Colombes,35494/esat-betty-launay-moulin-vert-competences-et-handicap-92,e1837/">ESAT BETTY LAUNAY-MOULIN VERT</a></span> XXElement xe = xeHeader.XPathElement(".//span[@class='NOM']//a"); if (xe != null) { header.UrlDetail = zurl.GetUrl(url, xe.ExplicitXPathValue("@href")); header.Name = _trimFunc(xe.ExplicitXPathValue(".//text()")); } //<span class="VILLE">E.S.A.T.<br />Bois-Colombes (92)</span> xe = xeHeader.XPathElement(".//span[@class='VILLE']"); if (xe != null) { IEnumerator <string> texts = xe.DescendantTexts().GetEnumerator(); if (texts.MoveNext()) { header.Type = texts.Current.Trim(); } else { Trace.WriteLine("error companyType not found"); } if (texts.MoveNext()) { header.Location = texts.Current.Trim(); } else { Trace.WriteLine("error companyLocation not found"); } } // <span class="TELEPHONE">01 47 86 11 48</span> header.Phone = _trimFunc(xeHeader.ExplicitXPathValue(".//span[@class='TELEPHONE']//text()")); //<img info_bulle="Signataire de la charte Ethique et Valeurs" border="0" alt="/images/bullesGesat/pictoCharte.png" src="/images/bullesGesat/pictoCharte.png" style=" border: 0;" /> //<img info_bulle="Lauréat des trophées HandiResponsables 2013" border="0" alt="/images/bullesGesat/LAURIERS-OR-2013.png" src="/images/bullesGesat/LAURIERS-OR-2013.png" style=" border: 0;" /> header.Infos = xeHeader.XPathValues(".//img/@info_bulle").Select(_trimFunc).ToArray(); //_header.SetInfo(xeHeader.XPathValues(".//img/@info_bulle")); headers.Add(header); } data.Data = headers.ToArray(); return(data); }
public void Connexion() { if (_connexionFile == null) { throw new PBException("DebriderDebridLink connexion file is null"); } //if (_serverTimeFile == null) // throw new PBException("DebriderDebridLink server time file is null"); pb.Trace.WriteLine("{0:dd-MM-yyyy HH:mm:ss} - new connexion to debrid-link.fr", DateTime.Now); if (__trace) { pb.Trace.WriteLine("DebriderDebridLink.Connexion() :"); } string url = __url + string.Format("/token/{0}/new", _publicKey); HttpRequestParameters requestParameters = new HttpRequestParameters { Encoding = Encoding.UTF8 }; DateTime dt = DateTime.Now; Http.Http http = HttpManager.CurrentHttpManager.Load(new HttpRequest { Url = url }, requestParameters); BsonDocument result = BsonSerializer.Deserialize <BsonDocument>(http.ResultText); if (__trace) { pb.Trace.WriteLine(" result :"); pb.Trace.WriteLine(result.zToJson()); } DebridLinkConnexion connexion = new DebridLinkConnexion(); //DebridLinkServerTime serverTime = new DebridLinkServerTime(); connexion.ConnexionTime = dt; //string token = doc.zGet("value.token").zAsString(); connexion.Token = result.zGet("value.token").zAsString(); string validTokenUrl = result.zGet("value.validTokenUrl").zAsString(); //string key = doc.zGet("value.key").zAsString(); connexion.Key = result.zGet("value.key").zAsString(); int ts = result.zGet("ts").zAsInt(); connexion.ClientTime = dt; connexion.ServerTime = zdate.UnixTimeStampToDateTime(ts); connexion.ServerTimeGap = connexion.ServerTime - dt; connexion.ConnexionLifetime = _connexionLifetime; connexion.EndConnexionTime = connexion.ConnexionTime + GetConnexionTimespan(connexion.ConnexionLifetime) - TimeSpan.FromMinutes(5); if (__trace) { pb.Trace.WriteLine(" request time : \"{0:dd/MM/yyyy HH:mm:ss}\"", dt); pb.Trace.WriteLine(" result : \"{0}\"", result.zGet("result").zAsString()); pb.Trace.WriteLine(" token : \"{0}\"", connexion.Token); pb.Trace.WriteLine(" validTokenUrl : \"{0}\"", validTokenUrl); pb.Trace.WriteLine(" key : \"{0}\"", connexion.Key); pb.Trace.WriteLine(" server time : {0} - {1:dd/MM/yyyy HH:mm:ss}", ts, connexion.ServerTime); pb.Trace.WriteLine(" server time gap : {0}", connexion.ServerTimeGap); } // validTokenUrl : "https://secure.debrid-link.fr/user/2_2d481d8991e4db60f43d24d9d387b75699db7a0157182967/login" http = HttpManager.CurrentHttpManager.Load(new HttpRequest { Url = validTokenUrl }, requestParameters); // <script>if (window!=window.top) { top.location.href='https://secure.debrid-link.fr/login'; }</script> // <form action='' method='POST' class='form-horizontal'> // <input type='text' class='form-control' name='user'> // <input type='password' class='form-control' name='password'> // <select name='sessidTime' class='form-control'> // <option value='all' selected='selected'> Toujours</option> // ... // </select> // <input type='hidden' value='10_a3a206c4398f195283a4843d44f017f3211275e443747173' name='token'> // <button type='submit' name='authorizedToken' value='1' class='btn btn-dl'>Envoyer</button> // <input type='submit' style='display:none'> XXElement xeSource = http.zGetXDocument().zXXElement(); // le script n'est plus là dans la page html 24/03/2015 // script : if (window!=window.top) { top.location.href='https://secure.debrid-link.fr/login'; } //string script = xeSource.XPathValue("//head//script//text()"); //if (script == null) //{ // //Trace.WriteLine("//head//script not found"); // //return; // throw new PBException("DebriderDebridLink.Connect() : //head//script not found"); //} //if (__trace) // pb.Trace.WriteLine(" script : \"{0}\"", script); //Regex rg = new Regex("top\\.location\\.href=[\"'](.*)[\"']", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase); //Match match = rg.Match(script); //if (!match.Success) //{ // //Trace.WriteLine("top.location.href='...' not found in script"); // //return; // throw new PBException("DebriderDebridLink.Connect() : top.location.href='...' not found in script"); //} //url = match.Groups[1].Value; url = "https://secure.debrid-link.fr/login"; if (__trace) { pb.Trace.WriteLine(" login url : \"{0}\"", url); } XXElement xeForm = xeSource.XPathElement("//form"); string action = xeForm.AttribValue("action"); if (__trace) { pb.Trace.WriteLine(" form action : \"{0}\"", action); } if (action != null && action != "") { url = action; } HttpRequestMethod method = HttpTools.GetHttpRequestMethod(xeForm.AttribValue("method")); if (__trace) { pb.Trace.WriteLine(" form method : {0}", method); } StringBuilder content = new StringBuilder(); bool first = true; string name, value; foreach (XXElement xe in xeForm.DescendantFormItems()) { name = xe.AttribValue("name"); if (name == null) { continue; } if (name == "user") { value = _login; } else if (name == "password") { value = _password; } else if (name == "sessidTime") { value = GetConnexionLifetime(_connexionLifetime); } else { value = xe.AttribValue("value"); } if (!first) { content.Append('&'); } content.AppendFormat("{0}={1}", name, value); if (__trace) { if (name != "password") { pb.Trace.WriteLine(" {0}={1}", name, value); } else { pb.Trace.WriteLine(" {0}=xxx", name); } } first = false; } // "user=la_beuze&password=xxxxxx&sessidTime=all&token=10_56b51ee12ad5dabcac620230cda436cab94bd37154742765&authorizedToken=1" //if (__trace) // pb.Trace.WriteLine("content : \"{0}\"", content.ToString()); http = HttpManager.CurrentHttpManager.Load(new HttpRequest { Url = url, Method = method, Content = content.ToString() }, requestParameters); // <div class='panel-body'> // <div class='alert alert-success'> // La session a bien été activée. Vous pouvez utiliser l'application API Test // </div> // </div> xeSource = http.zGetXDocument().zXXElement(); //string loginMessage = xeSource.ExplicitXPathValue("//div[@class='panel-body']//text()"); string loginMessage = xeSource.ExplicitXPathValue("//div[@class='alert alert-success']//text()"); if (__trace) { pb.Trace.WriteLine(" login message : \"{0}\"", loginMessage); } //if (loginMessage == null || !loginMessage.Trim().StartsWith("La session a bien été activée", StringComparison.InvariantCultureIgnoreCase)) if (loginMessage == null || !loginMessage.Trim().StartsWith("Vous avez été connecté avec succès", StringComparison.InvariantCultureIgnoreCase)) { throw new PBException("DebriderDebridLink.Connect() : wrong login message \"{0}\"", loginMessage); } connexion.zSave(_connexionFile); _connexion = connexion; //serverTime.zSave(_serverTimeFile); //_serverTime = serverTime; }