readnews.c 完成的工作将写入几个文件:
oldnews.log (为了不重复导入新闻。 PS:第一次运行记得touch一个oldnews.log~~)
格式:
http://xxxxx.xxxxx/xxx.html (URL用于判重)
readnews.log (为下一步取新闻内容提供信息)
格式:
News M.1021475407.A
http://news.sina.com.cn/c/2002-05-15/2300576584.html版名 文件名 url
readnews处理完后就该英明神勇的 fetchnews.c上场了。
处于小弟一直使用Pascal数年,现在用C不熟,所以以下内容
建议大家最好不要看了(惨不忍睹啊……)
工具一:nohtml.c
#include <stdio.h>
int main()
{
int ch, tag = 0;
while((ch=getchar()) != EOF) {
if (ch == '<')
tag = 1;
if (!tag) putchar(ch);
if (ch == '>')
tag = 0;
}
}
工具二:getbody.c
注意:getbody是特别为sina.com设计的,不能括展
而且处理sina.com论坛的东西有问题。偶也难得改了.
#include <stdio.h>
#define MAX 20480
int main()
{
char buf[MAX];
int ch, i=0, start, end, j, isenter = 0;
char *p;
while ((i<MAX) && (ch = getchar()) != EOF)
buf[i++] = ch;
buf[i] = 0;
p = (char *)strstr(buf, "http");
if (p!=0)
start = strlen(buf) - strlen(p);
else {
printf("%s", buf);
return 0;
}
p = (char *)strstr(buf, " ");
if (p!=0)
end = strlen(buf) - strlen(p) -1;
else {
printf("%s", &buf[start]);
return 0;
}
for (i=start, j=0; i<end; i++) {
if ((buf[i] == '\t') || (buf[i] == '\n')) {
i++;
while ((i<end)&&((buf[i] == '\n')||(buf[i] == '\t')))
i++;
isenter = 1;
}
if (isenter) {
printf("\n");
isenter = 0;
}
printf("%c", buf[i]);
}
}
--
FROM AfterDark