c# - Get data from webpage using HtmlElement? -
i'm trying data game site winforms application. page i'm looking withdraw data this: http://www.tibia.com/community/?subtopic=characters&name=eternal+oblivion
my winforms program has search bar connected webbrowser. in search bar can type in name, example game character name "eternal oblivion". when hit search goes page (example: http://www.tibia.com/community/?subtopic=characters&name=eternal+oblivion).
in winforms application have table contains name, sex, vocation, level. 4 (to start with) - copy of profile page. how can data program? want in program:
name: eternal oblivion sex: male vocation: knight level: 297 this code i'm using doesn't work. seems tricky 1 because website doesn't use style name or w/e on table tags. why isn't bgcolor working? , also, code wouldn't work since repeat same thing on color , same on color b. see on website, http://www.tibia.com/community/?subtopic=characters&name=eternal+oblivion color on every 2nd line. how that?
if (this.browser.readystate == webbrowserreadystate.complete) { foreach (htmlelement cell in this.browser.document.getelementsbytagname("tr")) { string cls = cell.getattribute("bgcolor"); if (cls.startswith("#f1e0c6")) { dynamic oldname = cell.innertext; string[] strings = oldname.split('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); string charnameonly = strings[1]; labelname.text = charnameonly.tostring(); } else if (cls.startswith("#d4c0a1")) { dynamic oldsex = cell.innertext; string[] strings = oldsex.split('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); string charsexonly = strings[1]; labelsex.text = charsexonly.tostring(); } } }
i try different approach. once have html code of page in string, split based on looking for. example, character name:
string name = htmlcode .split(new string[] {"name:"}, stringsplitoptions.removeemptyentries)[1] .split('>')[2] .split('<')[0]; is not clean , nice, works , same other values looking for, change "name:" "sex:", "vocation:", etc...
Comments
Post a Comment