TidyNode UCHome_Main_SiteConst::next_feed(void *state_data, TidyDoc doc, TidyNode prev) { ParserStateObject *state_obj = (ParserStateObject*)state_data; TidyNode node = NULL; TidyNode node2 = NULL; int nid = 0; node = tidyGetNext(prev); if(node == NULL) { node = tidyGetParent(prev); assert(node != NULL); node2 = tidyGetNext(node); if(node2 == NULL) { return NULL; }else{ if(tidyNodeGetId(node2) == TidyTag_H4) { state_obj->curr_date = this->get_time_string(doc, node2); node = tidyGetNext(node2); if(node == NULL) { //null }else{ return tidyGetChild(node); } }else{ nid = tidyNodeGetId(node2); assert(nid == TidyTag_UL); return tidyGetChild(node2); } } }else{ return node; } return NULL; }
void dumpNode( TidyNode tnod, int indent ) { TidyNode child; for ( child = tidyGetChild(tnod); child; child = tidyGetNext(child) ) { ctmbstr name; switch ( tidyNodeGetType(child) ) { case TidyNode_Root: name = "Root"; break; case TidyNode_DocType: name = "DOCTYPE"; break; case TidyNode_Comment: name = "Comment"; break; case TidyNode_ProcIns: name = "Processing Instruction"; break; case TidyNode_Text: name = "Text"; break; case TidyNode_CDATA: name = "CDATA"; break; case TidyNode_Section: name = "XML Section"; break; case TidyNode_Asp: name = "ASP"; break; case TidyNode_Jste: name = "JSTE"; break; case TidyNode_Php: name = "PHP"; break; case TidyNode_XmlDecl: name = "XML Declaration"; break; case TidyNode_Start: case TidyNode_End: case TidyNode_StartEnd: default: name = tidyNodeGetName( child ); break; } assert( name != NULL ); TRACE( "------%d,%d, %s,%s", indent, indent, " ", name ); dumpNode( child, indent + 4 ); } }
QString UCHome_Main_SiteConst::find_photo_url(TidyDoc doc) { QString photo_url; TidyNode node; TidyNode node2; ctmbstr url_str = NULL; TidyAttr attr = NULL; //quick_update s_clear node = this->searchNode(doc, NULL, "quick_update s_clear", TidyTag_DIV); if(node != NULL) { node2 = tidyGetChild(node); Q_ASSERT(tidyNodeGetId(node2) == TidyTag_IMG); attr = tidyAttrGetById(node2, TidyAttr_SRC); if(attr != NULL) { url_str = tidyAttrValue(attr); photo_url = QString(url_str); photo_url = photo_url.replace("small", "big"); q_debug()<<"Photo url: "<<photo_url; }else{ } }else{ q_debug()<<"Warning: no photo url found"; } return photo_url; }
/* Traverse the document tree */ void dumpNode(TidyDoc doc, TidyNode tnod, int indent ) { TidyNode child; for ( child = tidyGetChild(tnod); child; child = tidyGetNext(child) ) { ctmbstr name = tidyNodeGetName( child ); if ( name ) { /* if it has a name, then it's an HTML tag ... */ TidyAttr attr; printf( "%*.*s%s ", indent, indent, "<", name); /* walk the attribute list */ for ( attr=tidyAttrFirst(child); attr; attr=tidyAttrNext(attr) ) { printf(tidyAttrName(attr)); tidyAttrValue(attr)?printf("=\"%s\" ", tidyAttrValue(attr)):printf(" "); } printf( ">\n"); } else { /* if it doesn't have a name, then it's probably text, cdata, etc... */ TidyBuffer buf; tidyBufInit(&buf); tidyNodeGetText(doc, child, &buf); printf("%*.*s\n", indent, indent, buf.bp?(char *)buf.bp:""); tidyBufFree(&buf); } dumpNode( doc, child, indent + 4 ); /* recursive */ } }
static void html_find_objects(TidyNode node, GSList** objs) { TidyNode child; gchar* url = NULL; const gchar* name = NULL; GHashTable* attrs = NULL; for (child = tidyGetChild(node); child; child = tidyGetNext(child)) { attrs = html_get_attributes(child); if ((name = tidyNodeGetName(child))) { if (g_ascii_strncasecmp(name, "img", 3) == 0) { url = html_parse_img(attrs); } else if (g_ascii_strncasecmp(name, "script", 6) == 0) { url = html_parse_script(attrs); } else if (g_ascii_strncasecmp(name, "link", 4) == 0) { url = html_parse_link(attrs); } g_hash_table_destroy(attrs); if (url != NULL) { *objs = g_slist_append(*objs, g_strdup(url)); url = NULL; } } html_find_objects(child, objs); } }
static nglString GetEncodingString(TidyNode tnod) { if (tidyNodeGetId(tnod) == TidyTag_META) { // Search for the encoding attribute TidyAttr attr_content = tidyAttrGetById(tnod, TidyAttr_CONTENT); TidyAttr attr_httpequiv = tidyAttrGetById(tnod, TidyAttr_HTTP_EQUIV); if (attr_content && attr_httpequiv) { nglString contenttype(tidyAttrValue(attr_content)); if (contenttype.Compare(_T("content-type"), false) != 0) { // bleh... } nglString encoding(tidyAttrValue(attr_content)); //NGL_OUT(_T("content found in the tree: %s"), encoding.GetChars()); int32 col = encoding.Find(_T("charset=")); encoding = encoding.Extract(col + 8); //NGL_OUT(_T("encoding found in the tree: %s"), encoding.GetChars()); return encoding; } } TidyNode child; for (child = tidyGetChild(tnod); child; child = tidyGetNext(child)) { nglString str(GetEncodingString(child)); if (!str.IsNull()) return str; } return nglString::Null; }
/* {{{ proto boolean tidyNode::hasChildren() Returns true if this node has children */ static TIDY_NODE_METHOD(hasChildren) { TIDY_FETCH_ONLY_OBJECT; if (tidyGetChild(obj->node)) { RETURN_TRUE; } else { RETURN_FALSE; } }
FeedRecord* UCHome_Main_SiteConst::parse_friend(void *state_data, TidyDoc doc, TidyNode node) { FeedRecord * rec = NULL; QString note; TidyBuffer tbuf; TidyNode node2 = NULL; TidyNode node3 = NULL; TidyNode node4 = NULL; TidyNode node5 = NULL; TidyAttr attr = NULL; ctmbstr fuid = NULL; ctmbstr fusername = NULL; tidyBufInit(&tbuf); tidyNodeGetText(doc, node, &tbuf); note = this->u8codec->toUnicode(QByteArray((char*)tbuf.bp)); rec = new FeedRecord(); rec->content = this->rewrite_relative_link(note); rec->content = "<table>" + rec->content + "</table>"; md5CheckSum((char*)tbuf.bp, tbuf.size, rec->md5sum); tidyBufFree(&tbuf); //q_debug()<<"Orig:"<<note; node2 = tidyGetChild(node); node3 = tidyGetChild(node2); attr = tidyAttrGetById(node3, TidyAttr_VALUE); fuid = tidyAttrValue(attr); node4 = tidyGetNext(node2); node3 = tidyGetChild(node4); // A node5 = tidyGetChild(node3); //IMG attr = tidyAttrGetById(node5, TidyAttr_ALT); fusername = tidyAttrValue(attr); rec->fuid = fuid; rec->fusername = this->u8codec->toUnicode(QByteArray(fusername)); q_debug()<<"USER:"<<fuid<<rec->fusername; md5CheckSum(fuid, strlen(fuid), rec->md5sum);//使用uid的md5值肯定不会出现冲突 return rec; }
static void traverseDeeper(TidyDoc doc, lua_State *L, TidyNode node) { TidyNode child; child = tidyGetChild ( node ); while ( child ) { traverseNodes(doc, L, child); child = tidyGetNext ( child ); } }
BOOL CCaHtmlParse::__IsFlightValid(const TidyNode & tdChild) { BOOL bValid = TRUE; TidyNode tRadioNode; CStringA straValid; tRadioNode = tidyGetChild(tdChild); straValid.Format("%s", GetAttValue(tRadioNode, "disabled")); if (0 == straValid.CompareNoCase("disabled")) bValid = FALSE; return bValid; }
static void traverseNode(TidyNode node, int level) { TidyNode child; /* first the callback function */ (*traverse_tidycall) (node, level, true); /* and now the children */ for (child = tidyGetChild(node); child; child = tidyGetNext(child)) traverseNode(child, level + 1); (*traverse_tidycall) (node, level, false); } /* traverseNode */
TidyNode UCHome_Main_SiteConst::first_feed(void *state_data, TidyDoc doc) { ParserStateObject *state_obj = (ParserStateObject*)state_data; TidyNode node = NULL; TidyNode node2 = NULL; //////// this->signtext = this->find_sign_text(doc); this->photourl = this->find_photo_url(doc); //this->sysnotes = this->find_sys_notice(doc); ////////////// node = this->searchNode(doc, NULL, "enter-content", TidyTag_DIV); if(node == NULL) { q_debug()<<"No feed node found"; return NULL; } node2 = tidyGetChild(node); assert(node2 != NULL); int nid = tidyNodeGetId(node2); if(nid == TidyTag_H4) { state_obj->curr_date = this->get_time_string(doc, node2); node = tidyGetNext(node2); if(node == NULL) { //null }else{ return tidyGetChild(node); } }else if(nid == TidyTag_UL) { node = tidyGetChild(node2); if(tidyNodeGetId(node) == TidyTag_LI) { return node; // okkkkkk } }else{ q_debug()<<"Unknown node type:"<<tidyNodeGetName(node2); } return NULL; }
void nuiHTMLNode::BuildTree(const void* _tdoc, const void* _tnod, nglTextEncoding encoding, bool ComputeStyle) { TidyDoc tdoc = (TidyDoc)_tdoc; TidyNode tnod = (TidyNode)_tnod; SetFromNode(_tdoc, _tnod, encoding, ComputeStyle); TidyNode child; for (child = tidyGetChild(tnod); child; child = tidyGetNext(child)) { nuiHTMLNode* pNode = new nuiHTMLNode(_tdoc, child, encoding, this, ComputeStyle); mChildren.push_back(pNode); pNode->BuildTree(tdoc, child, encoding, ComputeStyle); } }
QString UCHome_Main_SiteConst::find_sign_text(TidyDoc doc) { QString sign_text; TidyNode node; TidyNode node2; TidyBuffer tbuf; node = this->searchNode(doc, NULL, "state", TidyTag_DIV); if(node != NULL) { node2 = tidyGetChild(node); Q_ASSERT(tidyNodeGetId(node2) == TidyTag_A); tidyBufInit(&tbuf); if(tidyNodeGetText(doc, tidyGetChild(node2), &tbuf)) { sign_text = this->u8codec->toUnicode(QByteArray((char*)tbuf.bp)); sign_text = sign_text.trimmed(); q_debug()<<"Sign text:"<<sign_text; } tidyBufFree(&tbuf); }else{ q_debug()<<"Warning: no state sign text found"; } return sign_text; }
DFNode *fromTidyNode(DFDocument *htmlDoc, TidyDoc tdoc, TidyNode tnode) { switch (tidyNodeGetType(tnode)) { case TidyNode_Text: { char *value = copyTidyNodeValue(tnode,tdoc); DFNode *result = DFCreateTextNode(htmlDoc,value); free(value); return result; } case TidyNode_CDATA: break; case TidyNode_Comment: break; case TidyNode_Root: printf("Have root\n"); break; default: { const char *name = tidyNodeGetName(tnode); if (name == NULL) { printf("NULL name for %p, type %d\n",tnode,tidyNodeGetType(tnode)); return NULL; } const NamespaceDecl *namespaceDecl = DFNameMapNamespaceForID(htmlDoc->map,NAMESPACE_HTML); Tag tag = DFNameMapTagForName(htmlDoc->map,namespaceDecl->namespaceURI,name); DFNode *element = DFCreateElement(htmlDoc,tag); for (TidyAttr tattr = tidyAttrFirst(tnode); tattr != NULL; tattr = tidyAttrNext(tattr)) { const char *name = tidyAttrName(tattr); const char *value = tidyAttrValue(tattr); if (value == NULL) // Can happen in case of the empty string value = "";; Tag attrTag = DFNameMapTagForName(htmlDoc->map,namespaceDecl->namespaceURI,name); DFSetAttribute(element,attrTag,value); } for (TidyNode tchild = tidyGetChild(tnode); tchild != NULL; tchild = tidyGetNext(tchild)) { DFNode *child = fromTidyNode(htmlDoc,tdoc,tchild); if (child != NULL) DFAppendChild(element,child); } return element; } } return NULL; }
/* Traverse the document tree */ int dumpNode(TidyDoc doc, TidyNode tnod, int element, WeatherData *data ) { TidyNode child; for ( child = tidyGetChild(tnod); child; child = tidyGetNext(child) ) { element++; ctmbstr name = tidyNodeGetName( child ); if ( name ) { /* if it has a name, then it's an HTML tag ... */ //TidyAttr attr; //printf( "%*.*s%s ", indent, indent, "<", name); /* walk the attribute list */ //for ( attr=tidyAttrFirst(child); attr; attr=tidyAttrNext(attr) ) { //printf(tidyAttrName(attr)); //tidyAttrValue(attr)?printf("=\"%s\" ", //tidyAttrValue(attr)):printf(" "); //} //printf( ">\n"); } else { /* if it doesn't have a name, then it's probably text, cdata, etc... */ TidyBuffer buf; tidyBufInit(&buf); tidyNodeGetText(doc, child, &buf); //printf("[%d]%s\n", element, buf.bp?(char *)buf.bp:""); switch (element) { case 133: sscanf( (char*)buf.bp, "%lf", &(data->outsideTemp) ); break; case 159: sscanf( (char*)buf.bp, "%d", &(data->outsideHumidity)); break; case 301: sscanf( (char*)buf.bp, "%lf", &(data->dewPoint)); break; case 333: sscanf( (char*)buf.bp, "%lf", &(data->barometer)); break; case 391: // wind speed if ( sscanf( (char*)buf.bp, "%lf", &(data->instantWindSpeed)) == 0) { data->instantWindSpeed = 0; } break; case 417: // wind direction { char b[100]; int i,j=0; for ( i=0; i<strlen((char*)buf.bp); i++) { if ( isdigit( ((char*)buf.bp)[i])) { b[j] = ((char*)buf.bp)[i]; j++; } } b[j] = 0; sscanf( b, "%d", &(data->instantWindDirection)); } break; case 503: if ( sscanf( (char*)buf.bp, "%lf", &(data->avgWindSpeed_2min)) == 0 ) { data->avgWindSpeed_2min = 0; } break; case 533: if ( sscanf( (char*)buf.bp, "%lf", &(data->windGust_10min)) == 0 ) { data->windGust_10min = 0; } break; case 599: sscanf( (char*)buf.bp, "%lf", &(data->rainRate)); break; case 603: sscanf( (char*)buf.bp, "%lf", &(data->dailyRain)); break; case 625: sscanf( (char*)buf.bp, "%lf", &(data->lastHourRain)); break; } tidyBufFree(&buf); } element++; element = dumpNode( doc, child, element, data ); /* recursive */ } return element; }
static void tidy_add_default_properties(PHPTidyObj *obj, tidy_obj_type type) { TidyBuffer buf; TidyAttr tempattr; TidyNode tempnode; zval attribute, children, temp; PHPTidyObj *newobj; switch(type) { case is_node: if (!obj->std.properties) { rebuild_object_properties(&obj->std); } tidyBufInit(&buf); tidyNodeGetText(obj->ptdoc->doc, obj->node, &buf); ADD_PROPERTY_STRINGL(obj->std.properties, value, buf.bp, buf.size ? buf.size-1 : 0); tidyBufFree(&buf); ADD_PROPERTY_STRING(obj->std.properties, name, tidyNodeGetName(obj->node)); ADD_PROPERTY_LONG(obj->std.properties, type, tidyNodeGetType(obj->node)); ADD_PROPERTY_LONG(obj->std.properties, line, tidyNodeLine(obj->node)); ADD_PROPERTY_LONG(obj->std.properties, column, tidyNodeColumn(obj->node)); ADD_PROPERTY_BOOL(obj->std.properties, proprietary, tidyNodeIsProp(obj->ptdoc->doc, obj->node)); switch(tidyNodeGetType(obj->node)) { case TidyNode_Root: case TidyNode_DocType: case TidyNode_Text: case TidyNode_Comment: break; default: ADD_PROPERTY_LONG(obj->std.properties, id, tidyNodeGetId(obj->node)); } tempattr = tidyAttrFirst(obj->node); if (tempattr) { char *name, *val; array_init(&attribute); do { name = (char *)tidyAttrName(tempattr); val = (char *)tidyAttrValue(tempattr); if (name && val) { add_assoc_string(&attribute, name, val); } } while((tempattr = tidyAttrNext(tempattr))); } else { ZVAL_NULL(&attribute); } zend_hash_str_update(obj->std.properties, "attribute", sizeof("attribute") - 1, &attribute); tempnode = tidyGetChild(obj->node); if (tempnode) { array_init(&children); do { tidy_instanciate(tidy_ce_node, &temp); newobj = Z_TIDY_P(&temp); newobj->node = tempnode; newobj->type = is_node; newobj->ptdoc = obj->ptdoc; newobj->ptdoc->ref_count++; tidy_add_default_properties(newobj, is_node); add_next_index_zval(&children, &temp); } while((tempnode = tidyGetNext(tempnode))); } else { ZVAL_NULL(&children); } zend_hash_str_update(obj->std.properties, "child", sizeof("child") - 1, &children); break; case is_doc: if (!obj->std.properties) { rebuild_object_properties(&obj->std); } ADD_PROPERTY_NULL(obj->std.properties, errorBuffer); ADD_PROPERTY_NULL(obj->std.properties, value); break; } }
static void parse_html(TidyDoc tdoc, TidyNode tnod, const url_list_t *elem, int indent, FILE *outfile) { TidyNode child; TidyAttr attr; TidyAttrId attr_id = TidyAttr_UNKNOWN; TidyNodeType node_type; TidyTagId node_id; ctmbstr name; char *url, *relative_url = NULL; int found = 0; int get_html_link = (!option_values.depth || elem->level < option_values.depth); int get_int_html_link = (!option_values.depth || elem->level < option_values.depth+1); int get_ext_depends = ((!option_values.depth || elem->level < option_values.depth+1) && !option_values.no_html_dependencies); for (child = tidyGetChild(tnod); child; child = tidyGetNext(child)) { node_type = tidyNodeGetType(child); switch (node_type) { case TidyNode_Start: case TidyNode_StartEnd: node_id = tidyNodeGetId(child); if (get_html_link && (node_id == TidyTag_A || node_id == TidyTag_AREA || node_id == TidyTag_MAP)) { found = 1; attr_id = TidyAttr_HREF; } else if (get_int_html_link && (node_id == TidyTag_FRAME || node_id == TidyTag_IFRAME)) { found = 1; attr_id = TidyAttr_SRC; } else if (get_ext_depends) { if (node_id == TidyTag_LINK) { found = 1; attr_id = TidyAttr_HREF; } else if (node_id == TidyTag_IMG || node_id == TidyTag_SCRIPT) { found = 1; attr_id = TidyAttr_SRC; } else { found = 0; attr_id = TidyAttr_UNKNOWN; } } else { found = 0; attr_id = TidyAttr_UNKNOWN; } if (found && (attr = tidyAttrGetById(child, attr_id)) != NULL) { url = (char *) tidyAttrValue(attr); string_free(relative_url); if (url && *url) add_new_url_and_check(elem, url, outfile ? &relative_url : NULL); } if (outfile && (name = tidyNodeGetName(child)) != NULL) { fprintf(outfile, "%*.*s%s", indent, indent, "<", name); for (attr = tidyAttrFirst(child); attr; attr = tidyAttrNext(attr)) { fprintf(outfile, " %s", tidyAttrName(attr)); if (relative_url && (tidyAttrGetId(attr) == attr_id)) fprintf(outfile, "=\"%s\"", relative_url); else if (tidyAttrValue(attr)) fprintf(outfile, "=\"%s\"", tidyAttrValue(attr) ? tidyAttrValue(attr) : ""); else fprintf(outfile, "=\"\""); } string_free(relative_url); if (node_type == TidyNode_StartEnd) fprintf(outfile, "/>\n"); else { fprintf(outfile, ">\n"); parse_html(tdoc, child, elem, indent + 1, outfile); fprintf(outfile, "%*.*s%s>\n", indent + 1, indent + 1, "</", name); } } else { string_free(relative_url); parse_html(tdoc, child, elem, indent + 1, outfile); } break; case TidyNode_End: if (outfile) { if ((name = tidyNodeGetName(child)) != NULL) fprintf(outfile, "%*.*s/%s>\n", indent, indent, "<", name); } break; case TidyNode_Text: if (outfile) { TidyBuffer buf; TidyTagId parent_node_id = tidyNodeGetId(tnod); tidyBufInit(&buf); if (parent_node_id == TidyTag_SCRIPT || parent_node_id == TidyTag_STYLE) tidyNodeGetValue(tdoc, child, &buf); else tidyNodeGetText(tdoc, child, &buf); if (buf.bp) fprintf(outfile, "%s", (char *)buf.bp); tidyBufFree(&buf); } break; case TidyNode_Comment: if (outfile) { TidyBuffer buf; tidyBufInit(&buf); tidyNodeGetValue(tdoc, child, &buf); if (buf.bp) fprintf(outfile, "<!--%s-->\n", (char *)buf.bp); tidyBufFree(&buf); } break; case TidyNode_CDATA: if (outfile) { TidyBuffer buf; tidyBufInit(&buf); tidyNodeGetValue(tdoc, child, &buf); if (buf.bp) fprintf(outfile, "<![CDATA[%s]]>\n", (char *)buf.bp); tidyBufFree(&buf); } break; case TidyNode_DocType: if (outfile) { int pub = 0; fprintf(outfile, "<!DOCTYPE %s", tidyNodeGetName(child)); for (attr = tidyAttrFirst(child); attr; attr = tidyAttrNext(attr)) { if (!pub) { fprintf(outfile, " %s", tidyAttrName(attr)); if (!string_casecmp(tidyAttrName(attr), "PUBLIC")) pub = 1; } if (tidyAttrValue(attr)) fprintf(outfile, " \"%s\"", tidyAttrValue(attr)); } fprintf(outfile, ">\n"); } break; default: if (outfile) { TidyBuffer buf; tidyBufInit(&buf); tidyNodeGetValue(tdoc, child, &buf); if (buf.bp) fprintf(outfile, "%s", (char *)buf.bp); tidyBufFree(&buf); } break; } } }
int CCaHtmlParse::ParseCaHtmlFlights(std::list<SCaLowPriceFlightDetail*> & listFlight, const std::string& strHtmlData, const CStringA & straDCode, const CStringA & straACode, const SCaLowPriceFlightInfo* pLowPriceFlightInfo) { TidyDoc doc = tidyCreate(); tidySetCharEncoding(doc,"raw"); tidyParseString(doc,strHtmlData.c_str()); TidyNode tnRoot = tidyGetRoot(doc); TidyNode tFlightTab; TidyNode tdChild; int nIndexTd = 0; CTime tCurrent = CTime::GetCurrentTime(); SCaLowPriceFlightDetail *pfindFlight = NULL; if (FindNode(tnRoot,"class","CA_table mt_10 clear",tFlightTab)) { //循环解析结算价,tblPolicy下的每一个子节点即为一条结算价信息 TidyNode trFlight; int nIndexTr = 0; BOOL bValid = FALSE; CStringA straDPortCode = straDCode; CStringA straAPortCode = straACode; CStringA straFlightNo(""); CStringA straFlightStartDate(""); CStringA straSaleEndDate(""); CStringA straSaleEndTime(""); CStringA straFlightStartTime(""); UINT uPrice = 0; UINT uRemainTicket = 0; for ( trFlight = tidyGetChild(tFlightTab); trFlight; trFlight = tidyGetNext(trFlight) ) { if (0 == nIndexTr)//跳过表头 { nIndexTr++; continue; } nIndexTd = 0; bValid = FALSE; straFlightNo = ""; straFlightStartDate = ""; straSaleEndDate = ""; straSaleEndTime = ""; straFlightStartTime = ""; uPrice = 0; uRemainTicket = 0; for ( tdChild = tidyGetChild(trFlight); tdChild; tdChild = tidyGetNext(tdChild) ) { switch(nIndexTd) { case 0: { //选择,是否为disabled bValid = __IsFlightValid(tdChild); TRACE(_T("Flight valid:%d-"), bValid); } break; case 1: { //日期/航班号 //dumpNode(tdChild, 0); //TRACE(_T("\r\n")); __GetFlightNoAndFlightStartDate(straFlightNo, straFlightStartDate, doc, tdChild); TRACE("date:%s, no:%s-", straFlightStartDate, straFlightNo); //TRACE("%s\r\n", GetNodeContent(doc, tdChild)); } break; case 2: { //起降时间 //dumpNode(tdChild, 0); //TRACE(_T("\r\n")); //TRACE("%s\r\n", GetNodeContent(doc, tdChild)); __GetFlightStartTime(straFlightStartTime, doc, tdChild); } break; case 3: { //机场 //dumpNode(tdChild, 0); //TRACE(_T("\r\n")); //TRACE("%s\r\n", GetNodeContent(doc, tdChild)); if (__IsTwoAirPort(straDCode, straACode)) { __GetAirPortCode(straDPortCode, straAPortCode, doc, tdChild); if(straDPortCode.IsEmpty()) straDPortCode = straDCode; if(straAPortCode.IsEmpty()) straAPortCode = straACode; TRACE("%s->%s-", straDPortCode, straAPortCode); } } break; case 4: { //销售结束日期,时间 //dumpNode(tdChild, 0); //TRACE(_T("\r\n")); //TRACE("%s\r\n", GetNodeContent(doc, tdChild)); __GetSaleEndDate(straSaleEndDate, straSaleEndTime, doc, tdChild); TRACE("sale end date:%s, %s-", straSaleEndDate, straSaleEndTime); } break; case 5: { //团购价 //dumpNode(tdChild, 0); //TRACE(_T("\r\n")); //TRACE("%s\r\n", GetNodeContent(doc, tdChild)); //CStringA straSetPrice = GetNodeContent(doc, tdChild); //double fSetPrice = atof(straSetPrice.GetBuffer(0)); //straSetPrice.ReleaseBuffer(); //tidyRelease(doc); //return fSetPrice; __GetPriceAndRamainTicket(&uPrice, &uRemainTicket, doc, tdChild); TRACE("price:%d, remain %d seats", uPrice, uRemainTicket); } break; } nIndexTd++; } TRACE(_T("\r\n")); //截至日期之后的航班不抓取 //得到起飞日期 int nFlightStartYear = 2014; int nFlightStartMonth = 12; int nFlightStartDay = 12; GetYearMonthDay(straFlightStartDate, &nFlightStartYear, &nFlightStartMonth, &nFlightStartDay); CTime tStart(nFlightStartYear, nFlightStartMonth, nFlightStartDay, 0, 0, 0); //if (!m_bGetAllCaTuanFlight) //{ // if (tStart > m_tGetEndTime) // continue; //} // //double d6 = pLowPriceFlightInfo->iMinHangPrice * 0.6; //UINT u6 = (UINT)d6; ////6折以上普通团购退改签要收费(低价申请不受限制),所以不上 //if (uPrice > d6 && CA_TUAN_PRODUCT == pLowPriceFlightInfo->iProductType) //{ // bValid = FALSE; // uRemainTicket = 0; // continue; //} //相同日期、时间、班次的航班,只取最低价 BOOL bFind = __findCaFlight(&pfindFlight, straFlightStartDate, straDPortCode, straAPortCode, straFlightNo, listFlight); if (bFind) { int nCurPrice = (int)uPrice; //当前解析出的这个比上次解析出的便宜 if(pfindFlight->nPrice > nCurPrice) { if (uRemainTicket > m_nMinTicketWarnNum) { //当前票的数量充足时,用当前票的数量更新上次解析出的数量 pfindFlight->nRemainSeat = uRemainTicket; pfindFlight->nPrice = nCurPrice; pfindFlight = NULL; } } else //(pfindFlight->nPrice <= nCurPrice) { if(pfindFlight->nRemainSeat <= m_nMinTicketWarnNum) { pfindFlight->nRemainSeat = uRemainTicket; pfindFlight->nPrice = nCurPrice; pfindFlight = NULL; } } continue; } //保存解析出来的航班信息,调用者负责释放内存 if (bValid) { SCaLowPriceFlightDetail* pDetail = new SCaLowPriceFlightDetail; pDetail->straCompany = "CA"; pDetail->straFromCityCode = straDPortCode; pDetail->straToCityCode = straAPortCode; pDetail->straFlightNo = straFlightNo; pDetail->straFromDate = straFlightStartDate; //由于携程订单进入需要一定的时间,国航下班16:00下班,所以当天的票,第2天12:00之前的票,销售结束时间提前30分钟, //取销售间隔 int nSaleEndYear = 2014; int nSaleEndMonth = 12; int nSaleEndDay = 12; GetYearMonthDay(straSaleEndDate, &nSaleEndYear, &nSaleEndMonth, &nSaleEndDay); int nSaleEndHour = 12; int nSaleEndMin = 0; GetHourMinSec(straSaleEndTime, &nSaleEndHour, &nSaleEndMin); CTime tSaleEndDate(nSaleEndYear, nSaleEndMonth, nSaleEndDay, nSaleEndHour, nSaleEndMin, 0); CTimeSpan tSpan = tSaleEndDate - tCurrent; //end 取销售间隔 //得到起飞时间 int nFlightStartHour = 12; int nFlightStartMin = 0; GetHourMinSec(straFlightStartTime, &nFlightStartHour, &nFlightStartMin); CTime tFlightStartTime(nFlightStartYear, nFlightStartMonth, nFlightStartDay, nFlightStartHour, nFlightStartMin, 0); CTime tTimeKey(nFlightStartYear, nFlightStartMonth, nFlightStartDay, 12, 0, 0); //end 得到起飞时间 //今明两天的、起飞时间在12点之前、且是低价申请的,销售结束时间为 前一天的官网销售结束的前30分钟 if ((CA_TUAN_LOW_PRICE_APPLY_PRODUT == pLowPriceFlightInfo->iProductType) && (1 == tSpan.GetDays()))//明天的的低价申请 { if(tFlightStartTime <= tTimeKey)//明天12起飞的低价申请, 今天下午3:25前有效(国航4点下班) { pDetail->straSaleEndDate.Format("%d-%02d-%02d", tCurrent.GetYear(), tCurrent.GetMonth(), tCurrent.GetDay()); CTime tSaleEnd(tCurrent.GetYear(), tCurrent.GetMonth(), tCurrent.GetDay(), 15, 25, 0); pDetail->straSaleEndTime.Format("%02d:%02d:%02d", tSaleEnd.GetHour(), tSaleEnd.GetMinute(), 0); } else//明天12后起飞的低价申请,明早可以出票 { pDetail->straSaleEndDate = straSaleEndDate; pDetail->straSaleEndTime.Format("%02d:%02d:%02d", nSaleEndHour, nSaleEndMin, 0); } } else if ((CA_TUAN_LOW_PRICE_APPLY_PRODUT == pLowPriceFlightInfo->iProductType) && (tSpan.GetDays() < 1))//今天的的低价申请,今天下午3:30前有效(国航4点下班) { pDetail->straSaleEndDate.Format("%d-%02d-%02d", tCurrent.GetYear(), tCurrent.GetMonth(), tCurrent.GetDay()); CTime tSaleEnd(tCurrent.GetYear(), tCurrent.GetMonth(), tCurrent.GetDay(), 15, 30, 0); pDetail->straSaleEndTime.Format("%02d:%02d:%02d", tSaleEnd.GetHour(), tSaleEnd.GetMinute(), 0); } else//普通团购,后天及以后的低价申请 { pDetail->straSaleEndDate = straSaleEndDate; pDetail->straSaleEndTime.Format("%02d:%02d:%02d", nSaleEndHour, nSaleEndMin, 0); } //政策销售时间到,删除政策 GetYearMonthDay(pDetail->straSaleEndDate, &nSaleEndYear, &nSaleEndMonth, &nSaleEndDay); int nSaleEndSec = 0; GetHourMinSec(pDetail->straSaleEndTime, &nSaleEndHour, &nSaleEndMin, &nSaleEndSec); CTime tPolicyDeleteTime(nSaleEndYear, nSaleEndMonth, nSaleEndDay, nSaleEndHour, nSaleEndMin, nSaleEndSec); if (tCurrent >= tPolicyDeleteTime) uRemainTicket = 0; pDetail->nPrice = uPrice; pDetail->nProductId = pLowPriceFlightInfo->iProductId; pDetail->nRemainSeat = uRemainTicket; pDetail->nProductType = pLowPriceFlightInfo->iProductType; listFlight.push_back(pDetail); } } } tidyRelease(doc); return -1.0; }