Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.file;
- import std.net.curl;
- import std.stdio;
- import std.string;
- import std.algorithm;
- //enum SITE_URL="http://www.myscore.ru/match/rR0Svyxr/#h2h;overall";
- enum SITE_HEADERS="User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:45.0) Gecko/20100101 Firefox/45.0";
- // словарик с результатами
- string[string] lastGames;
- // извлечение таблиц о последних событиях
- string extractTables(string contentOfPage)
- {
- auto startPosition = contentOfPage.indexOf("Последние игры:");
- contentOfPage = contentOfPage[startPosition+"Последние игры:".length..$];
- return contentOfPage[startPosition+1..$];
- }
- auto extractScores(string contentOfPage)
- {
- enum START_TAG = `<span class="score"><strong>`;
- enum END_TAG = `</strong></span>`;
- string[] dataAccumulator;
- auto extractTag(ref string s)
- {
- string result;
- auto startPosition = s.indexOf(START_TAG);
- s = s[startPosition..$];
- auto endPosition = s.indexOf(END_TAG);
- result = s[START_TAG.length..endPosition];
- s = s[endPosition + END_TAG.length..$];
- return result;
- }
- while (contentOfPage.indexOf(START_TAG) != -1)
- {
- string data = extractTag(contentOfPage);
- dataAccumulator ~= data;
- }
- return dataAccumulator;
- }
- string[string] getLastGames(string pageContents)
- {
- return lastGames;
- }
- void main()
- {
- auto contentOfPage = cast(string) std.file.read(`C:\projects\myscore.html`);
- contentOfPage
- .extractTables
- .extractScores
- .writeln;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement