Html敏捷包解析oid

本文关键字:oid 包解析 Html | 更新日期: 2023-09-27 18:05:50

完整的html代码:http://pastebin.com/WLwDCVZ0

我用敏捷包解析了所需的节点。代码:

var html = new HtmlDocument();
html.LoadHtml(request.Get("http://www.odnoklassniki.ru").ToString());
var h1 = html.DocumentNode.SelectSingleNode(@"/html[1]/body[1]/div[1]/div[3]/div[2]");
h1包含:

<!--{"uid":"aocrgdowcvpgtiymx0qqvblirnscijwdrcw","toolbar":true,"restrictedNIM":false,"restrictedMusic":false,"massUploadFix":true,"valentineActive":false,"navFactoryReqTimeout":3000,"discussionsRestricted":false,"share.urlPattern":"((?:(?:https?|ftp)://|(?:mailto:)?[-''w!#$%'u0026'*+/'u003d?^`{|}~][-''w!#$%'u0026'*+/'u003d?^`{|}~''.]*@)?(?:(?:(?:(?:[''wа-яА-Я-]+)''.){1,5})(?:com|net|org|biz|info|name|pro|asia|aero|cat|coop|eco|jobs|mobi|museum|post|tel|travel|xxx|edu|gov|int|mil|рф|испытание|xn--[''w-]*|[a-z]{2})|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)''.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?::''d{1,5})?(?:/(?:[''w/а-яА-Я''-''.,/~!#$%'u0026*+;:'u003d?''['']'@()]*[''wа-яА-Я/])?)?)","friendOnlinePopupDuration":25000,"premIc":true,"tinkoffPromoLink":"http://www.odnoklassniki.ru/apps/Tinkoff?tcsbanner'u003dodn_ok_bonus","valentineSamePresentIconRotateDelay":100,"configToolbarShowSpamExplanation":false,"lastName":"Иванова","menuWait":100,"configToolbarNotificationsEnableUnsubscribeAppEventsButton":true,"video.player.url":"http://stg.odnoklassniki.ru/static/odklvp/0-0-83/odklvp.swf?preferHd'u003d1'u0026noUpload'u003d1","menuBrief":true,"menuShow":500,"d_disc_ids":{"USER_ALBUM":6,"MOVIE":9,"USER_PHOTO":4,"SCHOOL_FORUM":10,"CITY_NEWS":13,"GROUP_TOPIC":1,"USER_FORUM":5,"USER_2LVL_FORUM":7,"SHARE":8,"GROUP_MOVIE":12,"GROUP_PHOTO":2,"HAPPENING_TOPIC":11,"CHAT":14,"USER_STATUS":3},"n.f.collapseEnabled":false,"pcId":"aocrgdowcvpgtiymx0aosttobwcoktbnwll","maxUsersInPopup":3,"notificationsRestricted":false,"toolbarNotificationsHideEnabled":true,"showSendOverlayLink":false,"visaOnlinePromoLink":"http://odnoklassniki.ru/apps/online-payments-test?view'u003dvisapromo","video.up-meta.url":"http://in.video.mail.ru/","groupOffComments":true,"displayCloseLinkWithMFVisaPromo":true,"configHintEnter":false,"communitySpamEnabled":true,"isUSt":false,"restrictedDisc":false,"menuStrict":true,"mms.groupIds":["aocrgdowcvpgtiymx0rgqrvvkoexjbmjrgp","aocrgdowcvpgtiymx0rmdrfqrjqyjhmhkgts","aocrgdowcvpgtiymx0rbuixcrnynjvsiqopz"],"app.feature.openlinks.enabled":true,"oid":"567334127898","menuClose":100,"bannerTargeting":{"v":{"d":"25","r":"307","n":"Анжела","m":"1","i":"567334127898"},"u":"AAAAhBe/yRoAAAE9nXB67Xpb+4YKHvKyVcA+tuqR8z8'u003d","t":"obLD1AAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAQAAAAAABkBxQcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAc'u003d"},"firstName":"Анжела","configToolabrRemoveConversation":true,"mpid":{"photoId":"491764025626"},"layoutConfig":"313542320128","friendOnlinePopupPosition":"right","dEnbl":true,"lbaidl":true,"male":false,"app.feature.openlinks.statuses.enabled":true,"overlayCategory":"1","restricted":false,"plainTooltips":true,"configHintSound":false,"dDelay":300000,"dItClosedSz":0,"dItSz":3,"dDelayPd":600000,"hasWishList":false,"overlayLinkGenderMask":2,"configToolbarSmilesVersion2":true}-->

如果我必须获得oid值(567334127898)到var,接下来我需要做什么?

Html敏捷包解析oid

我假设oid只能包含数字?如果我说错了请指正。

var match = Regex.Match(h1,"'"oid'":'"(?<oid>''d+)'"");
string oid = match.Groups["oid"].Value;
Console.WriteLine(oid);

其中h1是节点的内容(作为字符串),你正在解析Html敏捷包

在HTML注释中有一个JSON字符串

你可以用Newtonsoft。Json库。

删除html注释字符串:<!-- --> .

然后你可以像这样提取数字:

String JsonStr = "{'"uid'":'"aocrgdowcvpgtiymx0qqvblirnscijwdrcw'",'"toolbar'":true,'"restrictedNIM'":false,'"restrictedMusic'":false,'"massUploadFix'":true,'"valentineActive'":false,'"navFactoryReqTimeout'":3000,'"discussionsRestricted'":false,'"share.urlPattern'":'"((?:(?:https?|ftp)://|(?:mailto:)?[-''''w!#$%''u0026'*+/''u003d?^`{|}~][-''''w!#$%''u0026'*+/''u003d?^`{|}~''''.]*@)?(?:(?:(?:(?:[''''w'u0430-'u044F'u0410-'u042F-]+)''''.){1,5})(?:com|net|org|biz|info|name|pro|asia|aero|cat|coop|eco|jobs|mobi|museum|post|tel|travel|xxx|edu|gov|int|mil|'u0440'u0444|'u0438'u0441'u043F'u044B'u0442'u0430'u043D'u0438'u0435|xn--[''''w-]*|[a-z]{2})|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)''''.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?::''''d{1,5})?(?:/(?:[''''w/'u0430-'u044F'u0410-'u042F''''-''''.,/~!#$%''u0026*+;:''u003d?''''['''']'@()]*[''''w'u0430-'u044F'u0410-'u042F/])?)?)'",'"friendOnlinePopupDuration'":25000,'"premIc'":true,'"tinkoffPromoLink'":'"http://www.odnoklassniki.ru/apps/Tinkoff?tcsbanner''u003dodn_ok_bonus'",'"valentineSamePresentIconRotateDelay'":100,'"configToolbarShowSpamExplanation'":false,'"lastName'":'"'u0418'u0432'u0430'u043D'u043E'u0432'u0430'",'"menuWait'":100,'"configToolbarNotificationsEnableUnsubscribeAppEventsButton'":true,'"video.player.url'":'"http://stg.odnoklassniki.ru/static/odklvp/0-0-83/odklvp.swf?preferHd''u003d1''u0026noUpload''u003d1'",'"menuBrief'":true,'"menuShow'":500,'"d_disc_ids'":{'"USER_ALBUM'":6,'"MOVIE'":9,'"USER_PHOTO'":4,'"SCHOOL_FORUM'":10,'"CITY_NEWS'":13,'"GROUP_TOPIC'":1,'"USER_FORUM'":5,'"USER_2LVL_FORUM'":7,'"SHARE'":8,'"GROUP_MOVIE'":12,'"GROUP_PHOTO'":2,'"HAPPENING_TOPIC'":11,'"CHAT'":14,'"USER_STATUS'":3},'"n.f.collapseEnabled'":false,'"pcId'":'"aocrgdowcvpgtiymx0aosttobwcoktbnwll'",'"maxUsersInPopup'":3,'"notificationsRestricted'":false,'"toolbarNotificationsHideEnabled'":true,'"showSendOverlayLink'":false,'"visaOnlinePromoLink'":'"http://odnoklassniki.ru/apps/online-payments-test?view''u003dvisapromo'",'"video.up-meta.url'":'"http://in.video.mail.ru/'",'"groupOffComments'":true,'"displayCloseLinkWithMFVisaPromo'":true,'"configHintEnter'":false,'"communitySpamEnabled'":true,'"isUSt'":false,'"restrictedDisc'":false,'"menuStrict'":true,'"mms.groupIds'":['"aocrgdowcvpgtiymx0rgqrvvkoexjbmjrgp'",'"aocrgdowcvpgtiymx0rmdrfqrjqyjhmhkgts'",'"aocrgdowcvpgtiymx0rbuixcrnynjvsiqopz'"],'"app.feature.openlinks.enabled'":true,'"oid'":'"567334127898'",'"menuClose'":100,'"bannerTargeting'":{'"v'":{'"d'":'"25'",'"r'":'"307'",'"n'":'"'u0410'u043D'u0436'u0435'u043B'u0430'",'"m'":'"1'",'"i'":'"567334127898'"},'"u'":'"AAAAhBe/yRoAAAE9nXB67Xpb+4YKHvKyVcA+tuqR8z8''u003d'",'"t'":'"obLD1AAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAQAAAAAABkBxQcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAc''u003d'"},'"firstName'":'"'u0410'u043D'u0436'u0435'u043B'u0430'",'"configToolabrRemoveConversation'":true,'"mpid'":{'"photoId'":'"491764025626'"},'"layoutConfig'":'"313542320128'",'"friendOnlinePopupPosition'":'"right'",'"dEnbl'":true,'"lbaidl'":true,'"male'":false,'"app.feature.openlinks.statuses.enabled'":true,'"overlayCategory'":'"1'",'"restricted'":false,'"plainTooltips'":true,'"configHintSound'":false,'"dDelay'":300000,'"dItClosedSz'":0,'"dItSz'":3,'"dDelayPd'":600000,'"hasWishList'":false,'"overlayLinkGenderMask'":2,'"configToolbarSmilesVersion2'":true}";
Newtonsoft.Json.Linq.JContainer Properties = Newtonsoft.Json.JsonConvert.DeserializeObject(JsonStr) as Newtonsoft.Json.Linq.JContainer;
Newtonsoft.Json.Linq.JToken jToken = Properties.SelectToken("oid");
String Number = jToken.ToString();