atm-irbis

myscores

Feb 12th, 2017
608
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import std.file;
  2. import std.net.curl;
  3. import std.stdio;
  4. import std.string;
  5. import std.algorithm;
  6.  
  7.  
  8. //enum SITE_URL="http://www.myscore.ru/match/rR0Svyxr/#h2h;overall";
  9. enum SITE_HEADERS="User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:45.0) Gecko/20100101 Firefox/45.0";
  10.  
  11. // словарик с результатами
  12. string[string] lastGames;
  13.  
  14. // извлечение таблиц о последних событиях
  15. string extractTables(string contentOfPage)
  16. {
  17.     auto startPosition = contentOfPage.indexOf("Последние игры:");
  18.     contentOfPage = contentOfPage[startPosition+"Последние игры:".length..$];
  19.     return contentOfPage[startPosition+1..$];
  20. }
  21.  
  22. auto extractScores(string contentOfPage)
  23. {
  24.     enum START_TAG = `<span class="score"><strong>`;
  25.     enum END_TAG = `</strong></span>`;
  26.     string[] dataAccumulator;
  27.  
  28.     auto extractTag(ref string s)
  29.     {
  30.         string result;
  31.        
  32.         auto startPosition = s.indexOf(START_TAG);
  33.         s = s[startPosition..$];
  34.         auto endPosition = s.indexOf(END_TAG);
  35.         result = s[START_TAG.length..endPosition];
  36.         s = s[endPosition + END_TAG.length..$];
  37.        
  38.         return result;
  39.     }
  40.  
  41.     while (contentOfPage.indexOf(START_TAG) != -1)
  42.     {
  43.         string data = extractTag(contentOfPage);
  44.         dataAccumulator ~= data;
  45.     }
  46.  
  47.     return dataAccumulator;
  48. }
  49.  
  50. string[string] getLastGames(string pageContents)
  51. {
  52.     return lastGames;
  53. }
  54.  
  55. void main()
  56. {
  57.     auto contentOfPage = cast(string) std.file.read(`C:\projects\myscore.html`);
  58.     contentOfPage
  59.         .extractTables
  60.         .extractScores
  61.         .writeln;
  62. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×