m765555 发表于 2011-6-16 17:57:08

提取网站内容乱码问题

我想读取http://baidu.lehecai.com/lottery/draw/list/50?lottery_type=50&page=1&ds=2011-01-01&de=2011-06-15中的源码,从中提取如图这样的数据来保存起来,供学习之用。

为什么以下代码在msgbox中正常,而写入到文本后好多是乱码,请教如何设置呢?
代码如下:#include <INet.au3>
$http = 'http://baidu.lehecai.com/lottery/draw/list/50?lottery_type=50&page=1&ds=2011-01-01&de=2011-06-15'
$sData = InetRead($http)

;$sData = _INetGetSource($http)

$Source = BinaryToString($sData, 4)
MsgBox(0, 0, $Source)
ClipPut($Source)
$ym=ClipGet()
FileWrite("01.txt",$ym)

daiyu116 发表于 2011-6-16 18:55:24

本帖最后由 daiyu116 于 2011-6-16 19:00 编辑

回复 1# m765555
这样试试呢?

#include <INet.au3>
$http = 'http://baidu.lehecai.com/lottery/draw/list/50?lottery_type=50&page=1&ds=2011-01-01&de=2011-06-15'
$sData = InetRead($http)

;$sData = _INetGetSource($http)

$Source = BinaryToString($sData, 4)
MsgBox(0, 0, $Source)
ClipPut($Source)
$ym=ClipGet()
infolog($ym,"c:\1.Log")

;创建记录文件并写入内容
Func infolog($string,$filePath_name)
        $file =FileOpen($filePath_name,137)
        ; 检查打开的文件可写
        If $file = -1 Then
                MsgBox(0, "错误", "不能创建或打开文件"&$filePath_name&",如无该文件,请手动创建"&$filePath_name&".如无法创建,程序也将继续运行!")
                Return -1
        EndIf
        $writeok=FileWriteLine($filePath_name,$string & @CRLF)
        If $writeok=1 Then
                FileClose($filePath_name)
                Return 1
        Else
                MsgBox(0, "错误","向文件"&$filePath_name&"写入错误,请检查文件是否只读属性!但并不妨碍程序继续运行!")
                Return 0
        EndIf
EndFunc

komaau3 发表于 2011-6-16 20:11:00

_INetGetSource就是inrterread和BinaryToString的结合,你这BinaryToString两次,当然会有乱码

m765555 发表于 2011-6-17 08:14:15

二楼的代码同样有乱码,再试试其它

www378660084 发表于 2011-6-18 21:45:33

帮你试了试,用ansi方式查看就不会乱码了.

joyue9 发表于 2011-6-18 21:54:14

学习了..顶一个
页: [1]
查看完整版本: 提取网站内容乱码问题