Skip to content

Commit fb5d19d

Browse files
author
fog
committed
! add link_type
1 parent 333d72b commit fb5d19d

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

doc/config.ini

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
[www.example.net]
2+
link_str_start = "<div id=\"list\">"
3+
link_str_end = "</div>"
4+
; 第一个括号匹配链接地址,第二个括号匹配章节名称
5+
link_pattern = "<dd><a href=\"([^\"]*)\">([^<]*)</a></dd>"
6+
; 括号匹配内容
7+
content_pattern = "<div id=\"content\">([^<]*)</div>"
8+
encode = "GBK"
9+
; 0 - linkAddr = url.scheme() + "://" + url.host() + sublink;
10+
; 1 - linkAddr = url.toString() + sublink;
11+
; 2 - linkAddr = strUrl.left(strUrl.lastIndexOf('/')) + "/" + sublink;
12+
link_type = 2
13+
114
[www.dawenxue.net]
215
link_str_start = "<div id=\"list\">"
316
link_str_end = "</div>"
@@ -76,3 +89,11 @@ link_str_start = "<div id=\"list\">"
7689
link_str_end = "</div>"
7790
link_pattern = "<dd><a href=\"/[0-9_]+/([^\"]*)\">([^<]*)</a></dd>"
7891
content_pattern = "<div id=\"content\">([^<]*)</div>"
92+
93+
[www.11kt.cn]
94+
link_str_start = "<dd><table "
95+
link_str_end = "</table></dd>"
96+
link_pattern = "<td class=\"L\"><a href=\"([^\"]*)\">([^<]*)</a></td>"
97+
content_pattern = "<dd id=\"contents\">([^<]*)</dd>"
98+
encode = "GBK"
99+
link_type = 2

src/app/worker.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ static const char * const KEY_LINK_STR_END = "link_str_end";
1515
static const char * const KEY_LINK_PATTERN = "link_pattern";
1616
static const char * const KEY_CONTENT_PATTERN = "content_pattern";
1717
static const char * const KEY_INTERVAL = "interval";
18+
static const char * const KEY_LINKTYPE = "link_type";
1819
static const char * const INDEX_PAGE_FNAME = "./index.html";
1920
static const char * const BOOK_PAGE_FNAME = "./page.html";
2021
static const char * const BOOK_SAVE_FNAME = "./out.txt";
@@ -87,12 +88,25 @@ bool Worker::requestBookPages(const QString &urlStr)
8788
QString title = match.captured(2);
8889
QString linkAddr;
8990
const QUrl &url = m_siteInfo.m_url;
90-
if (!urlStr.endsWith('/')) {
91-
// there is a file name exist
92-
linkAddr = url.scheme() + "://" + url.host() + sublink;
93-
} else {
94-
linkAddr = url.toString() + sublink;
91+
switch (m_siteInfo.m_linkType) {
92+
case 0: {
93+
linkAddr = url.scheme() + "://" + url.host() + sublink;
94+
break;
95+
}
96+
case 1: {
97+
linkAddr = url.toString() + sublink;
98+
break;
99+
}
100+
case 2: {
101+
QString strUrl = url.toString();
102+
int pos = strUrl.lastIndexOf('/');
103+
linkAddr = strUrl.left(pos) + "/" + sublink;
104+
break;
105+
}
106+
default:
107+
break;
95108
}
109+
96110
m_pageInfos.append(PageInfo(linkAddr, title));
97111
//qDebug() << link << title;
98112
}
@@ -185,6 +199,8 @@ bool Worker::loadSiteConfigs(const QUrl &url)
185199
m_siteInfo.m_linkPattern = cfg->value(KEY_LINK_PATTERN).toString();
186200
m_siteInfo.m_bookPattern = cfg->value(KEY_CONTENT_PATTERN).toString();
187201
m_siteInfo.m_interval = cfg->value(KEY_INTERVAL, 0).toInt();
202+
m_siteInfo.m_linkType = cfg->value(KEY_LINKTYPE, 0).toInt();
203+
188204
cfg->endGroup();
189205

190206
isSupport = true;

src/app/worker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct SiteInfo {
1515
QString m_linkPattern;
1616
QString m_bookPattern;
1717
int m_interval = 0;
18+
int m_linkType = 0;
1819
};
1920

2021
struct PageInfo {

0 commit comments

Comments
 (0)