找回密码
 加入
搜索
查看: 2996|回复: 7

看看这段函数,截取的怎么总是有乱码啊?

  [复制链接]
发表于 2008-10-16 17:19:28 | 显示全部楼层 |阅读模式
日,网页错误,无法贴au3代码,就这么贴吧:


===============================================
#include "Inet.au3"
MsgBox(64, "", xinhuanetNews("http://news.xinhuanet.com/world/2008-10/08/content_10164358.htm",200))
Func xinhuanetNews($url, $Count)
        If $url <> "" Then
                $html = _INetGetSource($url)
                $StartStr = "<FONT color=#0000ff>"
                $EndStr = "(编辑"
                $Start = StringInStr($html, $StartStr)
                $End = StringInStr($html, $EndStr)
                $html = StringMid($html, $Start, $End - $Start)
                $html = StringRegExpReplace($html, "<.*?>", "")
;~                 $html = StringRegExpReplace($html, "\s", "")
                $html = StringReplace($html, "&nbsp;", "")
                If StringLen($html) < 10 Then
                        Return ("False!")
                Else
                        Return (StringLeft($html, $Count)&"……")
                EndIf
        Else
                Return ("False!")
        EndIf
EndFunc   ;==>xinhuanetNews

=================================

以下是截取到的:


新华网消息:据德国《世界报》9月3日报道,人类的大脑中也有四季。

春天的舒畅自由、夏季的兴奋火热、秋季的多愁善感———它们确实存在:加拿大研究人员发现了一种根据不同季节在人脑中活跃程度不同的蛋白质。它在光照不足的季节会清除脑细胞间隙中的“炖趾啥?伞?-羟色胺。
冬季抑郁———这是情绪不好的人在道歉时常常脱口而出的话。不过它确实存在。同样存在的还有春天的舒畅自由、夏季的兴奋火热和秋季的……
发表于 2008-10-16 23:08:45 | 显示全部楼层
那是编码转换的问题

#include "Ie.au3"
MsgBox(64, "", xinhuanetNews("http://news.xinhuanet.com/world/2008-10/08/content_10164358.htm",200))
Func xinhuanetNews($url, $Count)
        If $url <> "" Then
                $html = _IECreate($url, 0, 0, 1, 0)
                                $html = _IEDocReadHTML($html)
                $StartStr = "<FONT color=#0000ff>"
                $EndStr = "(编辑"
                $Start = StringInStr($html, $StartStr)
                $End = StringInStr($html, $EndStr)
                $html = StringMid($html, $Start, $End - $Start)
                $html = StringRegExpReplace($html, "<.*?>", "")
;~                 $html = StringRegExpReplace($html, "\s", "")
                $html = StringReplace($html, " ", "")
                If StringLen($html) < 10 Then
                        Return ("False!")
                Else
                        Return (StringLeft($html, $Count)&"……")
                EndIf
        Else
                Return ("False!")
        EndIf
EndFunc   ;==>xinhuanetNews
 楼主| 发表于 2008-10-17 14:19:20 | 显示全部楼层
非常感谢,用您的代码确实没有乱码了。这样打开网页在读取会影响速度吧?若果等页面装载完成,很耗时间,不等有担心截取不完整?不知道这样理解对不对
发表于 2008-10-17 14:21:56 | 显示全部楼层
原帖由 starfee 于 2008-10-17 14:19 发表
非常感谢,用您的代码确实没有乱码了。这样打开网页在读取会影响速度吧?若果等页面装载完成,很耗时间,不等有担心截取不完整?不知道这样理解对不对

差不多是这样啦
发表于 2008-10-17 14:33:56 | 显示全部楼层
换个函数获取就行了,我也曾经因为乱码头痛了好长一段日子。这边共享一下
下边是获取==每日学口语(10月17日)   Don't let this get you down. 不要为此灰心丧气。==
#include <IE.au3>
Dim $htext,$line0,$line1,$tEnChn,$url
DailySentence()
Func DailySentence()        ;--2008/10/14修改
        Local $cbLengh
        $url = 'http://bj.dict.cn/'
        $url = _IECreate($url, 0, 0)
        $htext = _IEBodyReadHTML($url)
        _IEQuit($url)
        If $htext <> "" Then
                $htext=StringReplace($htext,"<!--daily","",1)
                $line0 = StringInStr($htext, "<i>")
                $line1 = StringInStr($htext, "<!--daily")
                $htext = StringMid($htext, $line0, $line1 - $line0)
                $line0 = StringInStr($htext, chr(34)&">")
                $line1 = StringInStr($htext, "</a>")
                $tEnChn = StringMid($htext, $line0 + 2, $line1 - $line0 - 2)
                MsgBox(0,"Daily Sentence!",$tEnChn)
        EndIf
EndFunc   ;==>DailySentence
发表于 2008-10-17 14:33:57 | 显示全部楼层
换个函数获取就行了,我也曾经因为乱码头痛了好长一段日子。这边共享一下
下边是获取==每日学口语(10月17日)   Don't let this get you down. 不要为此灰心丧气。==
#include <IE.au3>
Dim $htext,$line0,$line1,$tEnChn,$url
DailySentence()
Func DailySentence()        ;--2008/10/14修改
        Local $cbLengh
        $url = 'http://bj.dict.cn/'
        $url = _IECreate($url, 0, 0)
        $htext = _IEBodyReadHTML($url)
        _IEQuit($url)
        If $htext <> "" Then
                $htext=StringReplace($htext,"<!--daily","",1)
                $line0 = StringInStr($htext, "<i>")
                $line1 = StringInStr($htext, "<!--daily")
                $htext = StringMid($htext, $line0, $line1 - $line0)
                $line0 = StringInStr($htext, chr(34)&">")
                $line1 = StringInStr($htext, "</a>")
                $tEnChn = StringMid($htext, $line0 + 2, $line1 - $line0 - 2)
                MsgBox(0,"Daily Sentence!",$tEnChn)
        EndIf
EndFunc   ;==>DailySentence
发表于 2008-10-17 14:33:57 | 显示全部楼层
换个函数获取就行了,我也曾经因为乱码头痛了好长一段日子。这边共享一下
下边是获取==每日学口语(10月17日)   Don't let this get you down. 不要为此灰心丧气。==
#include <IE.au3>
Dim $htext,$line0,$line1,$tEnChn,$url
DailySentence()
Func DailySentence()        ;--2008/10/14修改
        Local $cbLengh
        $url = 'http://bj.dict.cn/'
        $url = _IECreate($url, 0, 0)
        $htext = _IEBodyReadHTML($url)
        _IEQuit($url)
        If $htext <> "" Then
                $htext=StringReplace($htext,"<!--daily","",1)
                $line0 = StringInStr($htext, "<i>")
                $line1 = StringInStr($htext, "<!--daily")
                $htext = StringMid($htext, $line0, $line1 - $line0)
                $line0 = StringInStr($htext, chr(34)&">")
                $line1 = StringInStr($htext, "</a>")
                $tEnChn = StringMid($htext, $line0 + 2, $line1 - $line0 - 2)
                MsgBox(0,"Daily Sentence!",$tEnChn)
        EndIf
EndFunc   ;==>DailySentence
 楼主| 发表于 2008-10-20 12:28:29 | 显示全部楼层
哈哈,我试试,只要没有乱码我就谢天谢地了。。。。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-23 11:25 , Processed in 0.080036 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表