To moderator: he russian too
okey I use it.
And how to handle the situation when we have 2 links on page with same href but one with target="_blank" and others without it?
Я же говорю плохое решение, тут подсказать не могу.
Any example of how to find <a> tag with specified href attribute?
тут тебе в помощь регекспы, примерный код будет таким: (выдираем все a таги с target=_blank)
Кстате я не уверен настчет квантификатора "*?" по идее должен быть ленивым( по спецификации) но работает или нет - не проверял.
- Code: Select all
wxString text; // тут будет содерться найденная подстрока(в данном регекспе это таг ссылки с бланком)
wxRegEx qRegex(_T("(?p)<a[[:space:]][[:cntrl:][:print:]йцукенгшщзхъэждлорпавыфячсмитьбюёЁЙЦУКЕНГШЩЗХЪЭЖДЛОРПАВЫФЯЧСМИТЬБЮ]*\\?target[[:space:]]{0,1}=[[:space:]]{0,1}['\"]{0,1}_blank['\"]{0,1}[^>]*\\?>"), wxRE_ADVANCED + wxRE_ICASE);
size_t offset = 0;
size_t len = wxStrlen(html);
int flags = 0;
while (len > 0 && qRegex.Matches(&html[offset], flags, len)) {
size_t matchoffset, matchlen;
qRegex.GetMatch(&matchoffset, &matchlen);
text = html.Mid(offset + matchoffset, matchlen);
/* теперь работаем с тагом(text) можно одним регекспом ограничится, и это будет правильно, но я хз что там тебе для твоих целей понадобится, поэтому для пример привел такой*/
if (matchlen > 0) {
offset += matchoffset + matchlen;
len -= matchoffset + matchlen;
} else {
// Zero-width match
offset++;
len--;
}
flags = wxRE_NOTBOL;
}
--
And how to handle the situation when we have 2 links on page with same href but one with target="_blank" and others without it?
I say a bad decision, then I can not tell.
Any example of how to find <a> tag with specified href attribute?
Something like this:
- Code: Select all
wxString text;
wxRegEx qRegex(_T("(?p)<a[[:space:]][[:cntrl:][:print:]йцукенгшщзхъэждлорпавыфячсмитьбюёЁЙЦУКЕНГШЩЗХЪЭЖДЛОРПАВЫФЯЧСМИТЬБЮ]*\\?target[[:space:]]{0,1}=[[:space:]]{0,1}['\"]{0,1}_blank['\"]{0,1}[^>]*\\?>"), wxRE_ADVANCED + wxRE_ICASE);
size_t offset = 0;
size_t len = wxStrlen(html);
int flags = 0;
while (len > 0 && qRegex.Matches(&html[offset], flags, len)) {
size_t matchoffset, matchlen;
qRegex.GetMatch(&matchoffset, &matchlen);
text = html.Mid(offset + matchoffset, matchlen)
// work with tag <a...target=_blank>(string text)
if (matchlen > 0) {
offset += matchoffset + matchlen;
len -= matchoffset + matchlen;
} else {
// Zero-width match
offset++;
len--;
}
flags = wxRE_NOTBOL;
}
---
Отредактированно:
Ой, нафиг эти регекспы писал))) тебе же найти с определенным урлом надо, но смысл тот же - урл в регексп и смотреть есть ли совпадения(matches), можно наоборот использовать то что я написал и создать масив того что открывается в новом табе, ну и соответственно после нажатия ссылки сравнивать с массивом. Но тут тоже свои но, если хранить массив, то на каждый таб памяти не наберешься(хотя хранить достаточно урлы ведь?!), а если нет, то столкнешься с замедлением работы, т.к. поиск то время занимает. ( так что тут решай сам, как будет оптимальнее)
Edited:
You also find a certain urlom necessary, but the meaning is the same - the URL in the Extended version and see whether there is a match (matches), you can use on the contrary what I wrote and create an array that is revealed in a new tab , well, respectively, after pressing the link to compare with the array. But here too, but its, if you store an array, then each tab rack memory does not (although the store is enough URLs you?!), And if not, then stolkneshsya with a slowdown of work, because search takes time. (So that then resolves itself, as would be the best)