看板SetupBBS
标 题Re: Maple奇摩新闻无法抓?
发信站育达绿忆情怀BBS (Fri Jun 4 14:23:51 2004)
转信站ptt!ctu-reader!ctu-peer!news.nctu!news.imydu!ydu.bbs
※ 引述《[email protected] (魔流剑~剑魔流~)》之铭言:
> ※ 引述《[email protected] (幸福洋溢的 paul ^^v.)》之铭言:
> > 可以到这边下载喔! ^^~
> > 由 BioStar 分享的程式
> > http://bbs.bio.ncue.edu.tw/bbs_src/enews-open.c
> > 或是到 Maple_itoc 下载新的程式档
> > http://home.pchome.com.tw/soho/itoc/
> 奇摩新闻是又改了吗?!
> 又不能抓了耶....新版的程式有作修正吗?!
作者
[email protected] (澎湖小云雀) 看板 itoc
标题 Re: 奇摩新闻
时间 吟风‧眺月‧擎天岗 (2004/05/21 Fri 03:40:51)
这样改就可以去索取最新的新闻!
(「更多新闻」那里的新闻比较新且多)
:util/enews-open.c:html_download()
static void
html_fetch(fpath, kind) /* 将这档案中有效的连结找出来 */
char *fpath;
char kind; /* 种类 */
{
static int chrono = 0;
FILE *fp;
char folder[64], buf[65536];
char *start, *str1, *str2, *str3, *strA, *strB, *strC;
ENEWS enews;
int article_num;
if (!(fp = fopen(fpath, "r")))
return;
sprintf(folder, "run/kimo/%c/.ENEWS", kind);
unlink(folder); /* 重建一个新的 */
#if 0
处理 HTML 格式如下:
<a href=/040520/43/nxn9.html><big>胡锦涛重申﹁和平统一﹂政策</big></a><font c
olor=#666666><small>(中央社 2004/05/20 23:37)</small>
#endif
article_num = 0;
while (fgets(buf, 65535, fp) && !strstr(buf, "<tr><tr><td align=right valign=
top>•</td>"))
;
start = buf;
while (article_num <= 16 && strstr(start, "<a href=/"))
{
str1 = strstr(start, "<a href=/") + 9; /* 连结的起点位置 */
str2 = strstr(start, "<big>") + 5; /* 标题的起点位置 */
strA = strstr(str1, ">");
strB = strstr(str2, "</big>");
strC = strstr(str3, ")</small>");
*strA = '\0';
*strB = '\0';
*strC = '\0';
/* 加入 record */
memset(&enews, 0, sizeof(ENEWS));
enews.chrono = ++chrono; /* 每篇文章一个编号 */
enews.kind = kind;
sprintf(enews.xname, "A%06d%c", chrono, kind);
sprintf(enews.link, "
http://tw.news.yahoo.com/%s", str1);
str_ncpy(enews.title, str2, sizeof(enews.title));
str_ncpy(source, str3, sizeof(source));
if (!rec_add(folder, &enews, sizeof(ENEWS)))
html_download(&enews);
article_num++;
start = strC + 1;
}
fclose(fp);
}
:util/enews-open.c:main()
int
main()
{
char kind;
char cmd[256];
char *class[12] =
{
"polity", "society", "international", "twoshore",
"finance", "entertain", "sports", "leisure",
"relaxation", "health", "technology", "odd"
};
chdir(BBSHOME)
/* 抓资料并分析之 */
for (kind = 'A'; kind <= 'L'; kind++)
{
sprintf(cmd, LYNX_PATH " '
http://tw.news.yahoo.com/more.php?newsclass=%s' >
tmp/kimo_index", class[kind - 'A']);
system(cmd);
html_fetch("tmp/kimo_index", kind);
unlink("tmp/kimo_index"); /* 清除暂存档 */
}
return 0;
}
--
转自 Maple_itoc 看板。 ^^~
--
我想..你已『用你的右手,在蓝色精灵的左手里。』 找到答案了 ^^/..
....
--
◤ ▆ `▆ ╭╯ ○ ╮-┴╯╮ ┼ ╮-┴╮ ▆ ▆ ` ◤◤ .- ' .-╲ ◣
◣◣◤◤ ╭╯-┬╯┤┴┴╭ ┼╭」四 ◣◣◤◤◣◣' .- .- ' ◣◣-◤
◣◣-◤◣-◤╰-╭│╯├ Θ │|┴ │ =|= ◣◣-◤◣-◤ 育达‧绿忆情怀 BBS ▆
◣▇▆▇╰-╮.╰|╯╯╮ο(。╮╯ 月 ╯/(乂 ▇╭-╯▇▆▇ bbs.ydu.edu.tw .◤
Au
thor:
paul 从 bbs.ydu.edu.tw 发表