| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 930 人关注过本帖
标题:问什么下面这个天气抓取程序不能运行呢?
只看楼主 加入收藏
郁郁界河
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-10-14
收藏
 问题点数:0 回复次数:12 
问什么下面这个天气抓取程序不能运行呢?
程序代码:
PUBLIC goForm
goForm = CREATEOBJECT("ShowWeather")
goForm.Show()


DEFINE CLASS ShowWeather AS Form

    Caption = "Weather Report[Hong Kong]"
    Width = 400
    Height = 340
    MaxButton = .F.
   
    ADD OBJECT Command1 AS CommandButton WITH ;
        Left = 300, ;
        Top = 290, ;
        Width = 80, ;
        Height = 27, ;
        Caption = "\<Refresh"
   
    PROCEDURE Init
        PRIVATE i, loObject
        LOCAL i, loObject
        FOR i = 1 TO 8
            THIS.AddObject("Image" + ALLTRIM(STR(i)), "Image")
            loObject = EVALUATE("THIS.Image" + ALLTRIM(STR(i)))
            WITH loObject
                .Left = 90*(IIF(i <= 4, i, i - 4) - 1) + 30
                .Top = IIF(i <= 4, 30, 160)
                .Width = 64
                .Height = 64
                .Stretch = 1
                .Visible = .T.
            ENDWITH
            THIS.AddObject("Label" + ALLTRIM(STR(i)) + "1", "Label")
            loObject = EVALUATE("THIS.Label" + ALLTRIM(STR(i)) + "1")
            WITH loObject
                .Left = 90*(IIF(i <= 4, i, i - 4) - 1) + 30
                .Top = IIF(i <= 4, 100, 230)
                .BackStyle = 0
                .Width = 64
                .Height = 18
                .Alignment = 2
                .ForeColor = IIF(i = 1, RGB(255, 0, 0), RGB(0, 0, 0))
                .FontBold = IIF(i = 1, .T., .F.)
                .Visible = .T.
            ENDWITH
            THIS.AddObject("Label" + ALLTRIM(STR(i)) + "2", "Label")
            loObject = EVALUATE("THIS.Label" + ALLTRIM(STR(i)) + "2")
            WITH loObject
                .Left = 90*(IIF(i <= 4, i, i - 4) - 1) + 30
                .Top = IIF(i <= 4, 115, 245)
                .BackStyle = 0
                .Width = 64
                .Height = 18
                .Alignment = 2
                .ForeColor = IIF(i = 1, RGB(255, 0, 0), RGB(0, 0, 0))
                .FontBold = IIF(i = 1, .T., .F.)
                .Visible = .T.
            ENDWITH
            THIS.AddObject("Label" + ALLTRIM(STR(i)) + "3", "Label")
            loObject = EVALUATE("THIS.Label" + ALLTRIM(STR(i)) + "3")
            WITH loObject
                .Left = 90*(IIF(i <= 4, i, i - 4) - 1) + 30
                .Top = IIF(i <= 4, 130, 260)
                .BackStyle = 0
                .Width = 64
                .Height = 18
                .Alignment = 2
                .ForeColor = IIF(i = 1, RGB(255, 0, 0), RGB(0, 0, 0))
                .FontBold = IIF(i = 1, .T., .F.)
                .Visible = .T.
            ENDWITH
        ENDFOR
        SET CENTURY ON
        SET DATE "YMD"
        THIS.GetWeatherReport()
    ENDPROC

    PROCEDURE GetWeatherReport
        PRIVATE laArray, i, loObject
        LOCAL laArray[1], i, loObject
        = GetWeather(@laArray)
        FOR i = 1 TO 8
            loObject = EVALUATE("THIS.Image" + ALLTRIM(STR(i)))
            IF laArray[i, 8] = .T.
                loObject.Picture = laArray[i, 7]
            ELSE
                loObject.Visible = .F.
            ENDIF
            loObject = EVALUATE("THIS.Label" + ALLTRIM(STR(i)) + "1")
            loObject.Caption = IIF(i = 1, "Today", DTOC(laArray[i, 1]))
            loObject = EVALUATE("THIS.Label" + ALLTRIM(STR(i)) + "2")
            loObject.Caption = laArray[i, 3]
            loObject = EVALUATE("THIS.Label" + ALLTRIM(STR(i)) + "3")
            loObject.Caption = IIF(i = 1, ALLTRIM(STR(laArray[i, 4])), ;
                ALLTRIM(STR(laArray[i, 4])) + "-" + ALLTRIM(STR(laArray[i, 5])))
        ENDFOR
    ENDPROC
   
    PROCEDURE Command1.Click
        THISFORM.GetWeatherReport()
    ENDPROC

ENDDEFINE



PROCEDURE GetWeather
    LPARAMETERS taArray
    #DEFINE WEATHER_MAIN_PAGE [http://xoap.]
    #DEFINE WEATHER_URL [http://xoap.*&dayf=10&par=0&prod=xoap&key=0&unit=m]
    #DEFINE IMAGE_PATH ADDBS(SYS(2023)) + "Weather\"
    PRIVATE llReturnValue, lcTempFile, lcData, i, lcImage, lnTemperature, lnTemperature1, lnTemperature2
    LOCAL llReturnValue, lcTempFile, lcData, i, lcImage, lnTemperature, lnTemperature1, lnTemperature2
    llReturnValue = .T.
    lcTempFile = ADDBS(SYS(2023)) + LEFT(SYS(2015), 8) + ".TMP"
    lcData = ""
    DIMENSION taArray[8, 8]
    FOR i = 1 TO ALEN(taArray, 1)
        taArray[i, 1] = DATE() + i - 1
        taArray[i, 2] = DOW(taArray[i, 1], 2)
        taArray[i, 3] = CDOW(taArray[i, 1])
        taArray[i, 4] = 0
        taArray[i, 5] = 0
        taArray[i, 6] = ""
        taArray[i, 7] = IMAGE_PATH + ALLTRIM(STR(i)) + ".GIF"
        taArray[i, 8] = .F.
    ENDFOR
    IF DIRECTORY(IMAGE_PATH) = .F.
        MKDIR (IMAGE_PATH)
    ENDIF
    TRY
        DECLARE Integer URLDownloadToFile IN URLMON.DLL Integer, String, String, Integer, Integer
    CATCH
        llReturnValue = .F.
    ENDTRY
    IF llReturnValue = .F.
        RETURN .F.
    ENDIF
    IF URLDownloadToFile(0, WEATHER_URL, lcTempFile, 0, 0) <> 0
        RETURN .F.
    ENDIF
    lcData = FILETOSTR(lcTempFile)
    IF FILE(lcTempFile) = .T.
        DELETE FILE (lcTempFile)
    ENDIF
    lcImage = ""
    lnTemperature = 0
    = GetTodayWeather(lcData, @lcImage, @lnTemperature)
    taArray[1, 6] = WEATHER_MAIN_PAGE + lcImage
    taArray[1, 4] = lnTemperature
    taarray[1, 5] = lnTemperature
    FOR i = 1 TO 7
        lcImage = ""
        lnTemperature1 = 0
        lnTemperature2 = 0
        = GetWeekWeather(lcData, i, @lcImage, @lnTemperature1, @lnTemperature2)
        taArray[i + 1, 6] = WEATHER_MAIN_PAGE + lcImage
        taArray[i + 1, 4] = lnTemperature1
        taarray[i + 1, 5] = lnTemperature2
    ENDFOR
    FOR i = 1 TO 8
        IF URLDownloadToFile(0, taArray[i, 6], taArray[i, 7], 0, 0) = 0
            taArray[i, 8] = .T.
        ENDIF
    ENDFOR
    RETURN .T.
ENDPROC

PROCEDURE GetTodayWeather
    LPARAMETERS tcData, tcImage, tnTemperature
    #DEFINE START_STRING [<table border=0 width=100%><tr><td width=50%>] + ;
        [<table border=0 cellspacing=3><tr><td width=40>]
    #DEFINE START_STRING_IMAGE [<img src="]
    #DEFINE END_STRING_IMAGE [">]
    #DEFINE START_STRING_TEMP [<br>]
    #DEFINE END_STRING_TEMP [<br>]
    PRIVATE lcString
    LOCAL lcString
    lcString = GetWordNum2(tcData, 1, START_STRING)
    tcImage = GetWordNum2(lcString, 1, START_STRING_IMAGE, END_STRING_IMAGE)
    lcString = GetWordNum2(lcString, 1, START_STRING_TEMP, END_STRING_TEMP)
    lcString = GetNumber(lcString)
    tnTemperature = INT(VAL(GETWORDNUM(lcString, 1, ",")))
    RETURN .T.
ENDPROC

PROCEDURE GetWeekWeather
    LPARAMETERS tcData, tnIndex, tcImage, tnTemperature1, tnTemperature2
    #DEFINE START_STRING2 [<table border=0 cellspacing=3 width=100%><tr><td width=50%>]
    #DEFINE START_STRING_IMAGE2 [<td width=40><img src="]
    #DEFINE END_STRING_IMAGE2 ["></td>]
    #DEFINE START_STRING_TEMP2 [<br>?放]
    #DEFINE END_STRING_TEMP2 [<br>]
    PRIVATE lcString
    LOCAL lcString
    lcString = GetWordNum2(tcData, 1, START_STRING2)
    tcImage = GetWordNum2(lcString, tnIndex, START_STRING_IMAGE2, END_STRING_IMAGE2)
    lcString = GetWordNum2(lcString, tnIndex, START_STRING_TEMP2, END_STRING_TEMP2)
    lcString = GetNumber(lcString)
    tnTemperature1 = INT(VAL(GETWORDNUM(lcString, 1, ",")))
    tnTemperature2 = INT(VAL(GETWORDNUM(lcString, 2, ",")))
    RETURN .T.
ENDPROC

PROCEDURE GetWordNum2
    LPARAMETERS tcString, tnIndex, tcLeft, tcRight
    PRIVATE lcString
    LOCAL lcString
    lcString = RIGHT(tcString, LEN(tcString) - AT(UPPER(tcLeft), UPPER(tcString), tnIndex) - LEN(tcLeft) + 1)
    IF EMPTY(tcRight) = .T.
        RETURN lcString
    ENDIF
    lcString = LEFT(lcString, AT(UPPER(tcRight), UPPER(lcString)) - 1)
    RETURN lcString
ENDPROC

PROCEDURE GetNumber
    LPARAMETERS tcString
    PRIVATE lcString, i
    LOCAL lcString, i
    lcString = ""
    FOR i = 1 TO LEN(tcString)
        IF BETWEEN(ASC(RIGHT(LEFT(tcString, i), 1)), 48, 57) = .T.
            lcString = lcString + RIGHT(LEFT(tcString, i), 1)
        ELSE
            IF EMPTY(lcString) = .F.
                IF RIGHT(lcString, 1) <> ","
                    lcString = lcString + ","
                ENDIF
            ENDIF
        ENDIF
    ENDFOR
    RETURN lcString
ENDPROC


关于VFP的天气问题

是我的网站错了吗?

图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: 天气 
2013-11-04 20:08
hu9jj
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:红土地
等 级:贵宾
威 望:400
帖 子:11857
专家分:43421
注 册:2006-5-13
收藏
得分:0 
从贴图来看应该是没有获得互联网中天气数据,建议重点检查一下网络是否联通、网站是否正确、连接参数是否正确等。

活到老,学到老!http://www.(该域名已经被ISP盗卖了)E-mail:hu-jj@
2013-11-05 07:42
郁郁界河
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-10-14
收藏
得分:0 
回复 2楼 hu9jj
还是出不了,是网站有问题吗?
两个网站是不是得输入一样的呢?
图片附件: 游客没有浏览图片的权限,请 登录注册
2013-11-05 09:52
b土木丁口
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:264
专家分:189
注 册:2013-9-12
收藏
得分:0 
路过
2013-11-05 14:55
hu9jj
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:红土地
等 级:贵宾
威 望:400
帖 子:11857
专家分:43421
注 册:2006-5-13
收藏
得分:0 
你有这个网站的连接参数(也就是数据接口)吗?重点检查一下是否正确。

活到老,学到老!http://www.(该域名已经被ISP盗卖了)E-mail:hu-jj@
2013-11-05 16:01
郁郁界河
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-10-14
收藏
得分:0 
回复 5楼 hu9jj
额。。不太明白
2013-11-07 12:05
linkhai
Rank: 1
等 级:新手上路
帖 子:23
专家分:5
注 册:2013-2-7
收藏
得分:0 
这个网站的接入点好像变了,用天气插件吧,方便简单。
weather.zip (2.39 KB)
2013-11-08 12:06
郁郁界河
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-10-14
收藏
得分:0 
回复 7楼 linkhai
有点偷懒。。。。这个,是不是我想编一个天气预报的软件只能用这样的插件呢?像敲代码的话不能实现吗?
2013-11-08 15:06
linkhai
Rank: 1
等 级:新手上路
帖 子:23
专家分:5
注 册:2013-2-7
收藏
得分:0 
呵呵,你帖上来的那个不也是抓取网站的数据吗?既然有简单的,何必搞那么复杂
2013-11-08 15:48
linkhai
Rank: 1
等 级:新手上路
帖 子:23
专家分:5
注 册:2013-2-7
收藏
得分:0 
回复 8楼 郁郁界河
再给你个思路吧。

调用桌面天气秀的dll抓取网上的天气信息,将天气信息转到自己软件的界面中。

VFP调用DLL,在梅子论坛上好像有的,你查查看。
2013-11-08 17:33
快速回复:问什么下面这个天气抓取程序不能运行呢?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040200 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved