ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
楼主: puresway

[求助] 请各位老师帮忙做个网页查询

[复制链接]

TA的精华主题

TA的得分主题

 楼主| 发表于 2011-3-9 23:26 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
各位朋友,晚安!

TA的精华主题

TA的得分主题

发表于 2011-3-10 00:07 | 显示全部楼层
安,打算回去休息了,明天再奋斗

TA的精华主题

TA的得分主题

 楼主| 发表于 2011-3-10 09:26 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2011-3-10 11:23 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2011-3-10 14:53 | 显示全部楼层
哪位老师能帮小弟写一下,xmyjk前辈已经把主要的代码写好了,哪位老师帮忙做一下,小弟对网页操作一窍不通

TA的精华主题

TA的得分主题

 楼主| 发表于 2011-3-10 17:09 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2011-3-10 23:32 | 显示全部楼层
勉强搞定
不过有个问题,
打开excel,首次进行查询,能得到结果图片,后续继续查询图片就不会更新了。
然后,必须要关闭excel,再重新打开才能对新的查询返回正确的图片
初步预计和缓存有关系,希望其他高手帮忙看看
代码如下,excel见附件
  1. Option Explicit
  2. Sub CommandButton1_Click()

  3. Dim Xmlhttp As Object, Adodb As Object

  4. Sheets(1).Image1.Picture = LoadPicture("")
  5. If Dir(ThisWorkbook.Path & "" & "1" & ".jpg") <> "" Then Kill (ThisWorkbook.Path & "" & "1" & ".jpg")

  6. Dim Strlcx As String, Strbjx As String, Strqijian As String
  7. Dim Lcx As String, Bjx As String, Qijian As String

  8. Strlcx = Trim(Range("c25").Value)
  9. Strbjx = Trim(Range("f25").Value)
  10. Strqijian = Trim(Range("c27").Value)

  11. Select Case Strlcx
  12.    Case "e理财投连B款"
  13.      Lcx = "118201"
  14.    Case "积极成长型账户"
  15.      Lcx = "506003"
  16.    Case "稳健收益型账户"
  17.      Lcx = "506001"
  18. End Select

  19. Select Case Strbjx
  20.    Case "上证指数"
  21.      Bjx = "SZ"
  22.    Case "上证180"
  23.      Bjx = "ZS000010"
  24.    Case "上证50"
  25.      Bjx = "ZS000016"
  26.    Case "上证基金指数"
  27.      Bjx = "ZS000011"
  28.    Case "国债指数"
  29.      Bjx = "ZS000012"
  30.    Case "沪深300"
  31.      Bjx = "ZS000300"
  32.    Case "中债指数"
  33.      Bjx = "ZZ"
  34.    Case "中小板指"
  35.      Bjx = "ZS399005"
  36.    Case "深证成指"
  37.      Bjx = "ZS399001"
  38.    Case "深证综指"
  39.      Bjx = "ZS399106"
  40.    Case "深证基金指数"
  41.      Bjx = "ZS399305"
  42.    Case "银华核心价值优选基金"
  43.      Bjx = "519001"
  44.    Case "华夏大盘精选基金"
  45.      Bjx = "000011"
  46.    Case "华夏复兴基金"
  47.      Bjx = "000031"
  48.    Case "华夏成长基金"
  49.      Bjx = "000001"
  50.    Case "交银成长基金"
  51.      Bjx = "519692"
  52.    Case "银华领先策略基金"
  53.      Bjx = "180013"
  54. End Select

  55. Select Case Strqijian
  56.    Case "10天"
  57.      Qijian = "10"
  58.    Case "30天"
  59.      Qijian = "30"
  60.    Case "90天"
  61.      Qijian = "90"
  62.    Case "180天"
  63.      Qijian = "180"
  64.     Case "1年"
  65.      Qijian = "1"
  66.     Case "3年"
  67.      Qijian = "3"
  68. End Select

  69. Dim Url As String
  70. Url = "http://mall.taikang.com/elicai/image.jsp?accountid=" & Lcx & "&fundcode=" & Bjx & "&period=" & Qijian

  71. Set Xmlhttp = CreateObject("Microsoft.XMLHTTP")
  72. Xmlhttp.Open "get", Url, False
  73. Xmlhttp.setRequestHeader "Content-Type", "text/html"
  74. Xmlhttp.Send ""
  75. Do Until Xmlhttp.ReadyState = 4
  76. DoEvents
  77. Loop

  78. Set Xmlhttp = Nothing

  79. Set Xmlhttp = CreateObject("Microsoft.XMLHTTP")
  80. Xmlhttp.Open "get", "http://mall.taikang.com/elicai/imageServlet", False
  81. Xmlhttp.setRequestHeader "Content-Type", "image/jpeg"
  82. Xmlhttp.Send ""
  83. Do Until Xmlhttp.ReadyState = 4
  84. DoEvents
  85. Loop

  86. If Xmlhttp.Status = 200 Then

  87. Set Adodb = CreateObject("ADODB.Stream")
  88.    With Adodb
  89.             .Type = 1
  90.             .Open
  91.             .write Xmlhttp.Responsebody
  92.             .savetofile ThisWorkbook.Path & "" & "1" & ".jpg", 2   '另存图片
  93.             .Close
  94. End With
  95. Sheets(1).Image1.Picture = LoadPicture(ThisWorkbook.Path & "" & "1" & ".jpg")

  96. Else
  97.   reportErr (Xmlhttp.Status)
  98. End If

  99. Set Xmlhttp = Nothing
  100. Set Adodb = Nothing
  101. If Dir(ThisWorkbook.Path & "" & "1" & ".jpg") <> "" Then Kill (ThisWorkbook.Path & "" & "1" & ".jpg")

  102. MsgBox "查询并加载图片成功!"


  103. End Sub

  104. Sub reportErr(lStatus As Integer)
  105.         Select Case lStatus
  106.             Case 400
  107.                 MsgBox "Bad Request", vbCritical, "连接错误"
  108.             Case 401
  109.                 MsgBox "Unauthorized", vbCritical, "连接错误"
  110.             Case 402
  111.                 MsgBox "Payment Required", vbCritical, "连接错误"
  112.             Case 403
  113.                 MsgBox "Forbidden", vbCritical, "连接错误"
  114.             Case 404
  115.                 MsgBox "Not Found", vbCritical, "连接错误"
  116.             Case 407
  117.               MsgBox "Proxy Authentication Required", vbCritical, "连接错误"
  118.             Case 408
  119.                 MsgBox "Request Timeout", vbCritical, "连接错误"
  120.             Case 503
  121.                 MsgBox "Service Unavailable", vbCritical, "连接错误"
  122.             Case Else
  123.               MsgBox "Can not reach by other reason", vbCritical, "连接错误"
  124.         End Select

  125. End Sub
复制代码

[ 本帖最后由 xmyjk 于 2011-3-11 00:11 编辑 ]

账户对比.rar

254.52 KB, 下载次数: 18

TA的精华主题

TA的得分主题

发表于 2011-3-11 01:14 | 显示全部楼层

谢谢ah2005老师的指导 ,可以用了

谢谢ah2005的指导:
出现问题的最大原因你说对了,没有加上清除COOKIE,DeleteUrlCacheEntry URL

增加API 引用wininet.dll的DeleteUrlCacheEntry函数去清楚缓存
修正后的代码如下,excel见附件:

  1. Option Explicit

  2. Private Declare Sub DeleteUrlCacheEntry Lib "wininet.dll" (ByVal lpszUrlName As String)


  3. Sub CommandButton1_Click()

  4. Dim Xmlhttp As Object, Adodb As Object

  5. Sheets(1).Image1.Picture = LoadPicture("")
  6. If Dir(ThisWorkbook.Path & "" & "1" & ".jpg") <> "" Then Kill (ThisWorkbook.Path & "" & "1" & ".jpg")

  7. Dim Strlcx As String, Strbjx As String, Strqijian As String
  8. Dim Lcx As String, Bjx As String, Qijian As String

  9. Strlcx = Trim(Range("c25").Value)
  10. Strbjx = Trim(Range("f25").Value)
  11. Strqijian = Trim(Range("c27").Value)

  12. Select Case Strlcx
  13.    Case "e理财投连B款"
  14.      Lcx = "118201"
  15.    Case "积极成长型账户"
  16.      Lcx = "506003"
  17.    Case "稳健收益型账户"
  18.      Lcx = "506001"
  19. End Select

  20. Select Case Strbjx
  21.    Case "上证指数"
  22.      Bjx = "SZ"
  23.    Case "上证180"
  24.      Bjx = "ZS000010"
  25.    Case "上证50"
  26.      Bjx = "ZS000016"
  27.    Case "上证基金指数"
  28.      Bjx = "ZS000011"
  29.    Case "国债指数"
  30.      Bjx = "ZS000012"
  31.    Case "沪深300"
  32.      Bjx = "ZS000300"
  33.    Case "中债指数"
  34.      Bjx = "ZZ"
  35.    Case "中小板指"
  36.      Bjx = "ZS399005"
  37.    Case "深证成指"
  38.      Bjx = "ZS399001"
  39.    Case "深证综指"
  40.      Bjx = "ZS399106"
  41.    Case "深证基金指数"
  42.      Bjx = "ZS399305"
  43.    Case "银华核心价值优选基金"
  44.      Bjx = "519001"
  45.    Case "华夏大盘精选基金"
  46.      Bjx = "000011"
  47.    Case "华夏复兴基金"
  48.      Bjx = "000031"
  49.    Case "华夏成长基金"
  50.      Bjx = "000001"
  51.    Case "交银成长基金"
  52.      Bjx = "519692"
  53.    Case "银华领先策略基金"
  54.      Bjx = "180013"
  55. End Select

  56. Select Case Strqijian
  57.    Case "10天"
  58.      Qijian = "10"
  59.    Case "30天"
  60.      Qijian = "30"
  61.    Case "90天"
  62.      Qijian = "90"
  63.    Case "180天"
  64.      Qijian = "180"
  65.     Case "1年"
  66.      Qijian = "1"
  67.     Case "3年"
  68.      Qijian = "3"
  69. End Select

  70. Dim Url As String
  71. Url = "http://mall.taikang.com/elicai/image.jsp?accountid=" & Lcx & "&fundcode=" & Bjx & "&period=" & Qijian

  72. Set Xmlhttp = CreateObject("Microsoft.XMLHTTP")
  73. Xmlhttp.Open "get", Url, False
  74. Xmlhttp.setRequestHeader "Content-Type", "text/html"
  75. Xmlhttp.Send ""
  76. Do Until Xmlhttp.ReadyState = 4
  77. DoEvents
  78. Loop

  79. Set Xmlhttp = Nothing

  80. Set Xmlhttp = CreateObject("Microsoft.XMLHTTP")
  81. Xmlhttp.Open "get", "http://mall.taikang.com/elicai/imageServlet", False
  82. Xmlhttp.setRequestHeader "Content-Type", "image/jpeg"
  83. Xmlhttp.Send ""
  84. Do Until Xmlhttp.ReadyState = 4
  85. DoEvents
  86. Loop

  87. If Xmlhttp.Status = 200 Then

  88. Set Adodb = CreateObject("ADODB.Stream")
  89.    With Adodb
  90.             .Type = 1
  91.             .Open
  92.             .write Xmlhttp.Responsebody
  93.             .savetofile ThisWorkbook.Path & "" & "1" & ".jpg", 2   '另存图片
  94.             .Close
  95. End With
  96. Sheets(1).Image1.Picture = LoadPicture(ThisWorkbook.Path & "" & "1" & ".jpg")

  97. Else
  98.   reportErr (Xmlhttp.Status)
  99. End If

  100. Set Xmlhttp = Nothing
  101. Set Adodb = Nothing


  102. DeleteUrlCacheEntry "http://mall.taikang.com/elicai/imageServlet"

  103. If Dir(ThisWorkbook.Path & "" & "1" & ".jpg") <> "" Then Kill (ThisWorkbook.Path & "" & "1" & ".jpg")

  104. MsgBox "查询并加载图片成功!"


  105. End Sub

  106. Sub reportErr(lStatus As Integer)
  107.         Select Case lStatus
  108.             Case 400
  109.                 MsgBox "Bad Request", vbCritical, "连接错误"
  110.             Case 401
  111.                 MsgBox "Unauthorized", vbCritical, "连接错误"
  112.             Case 402
  113.                 MsgBox "Payment Required", vbCritical, "连接错误"
  114.             Case 403
  115.                 MsgBox "Forbidden", vbCritical, "连接错误"
  116.             Case 404
  117.                 MsgBox "Not Found", vbCritical, "连接错误"
  118.             Case 407
  119.               MsgBox "Proxy Authentication Required", vbCritical, "连接错误"
  120.             Case 408
  121.                 MsgBox "Request Timeout", vbCritical, "连接错误"
  122.             Case 503
  123.                 MsgBox "Service Unavailable", vbCritical, "连接错误"
  124.             Case Else
  125.               MsgBox "Can not reach by other reason", vbCritical, "连接错误"
  126.         End Select

  127. End Sub
复制代码

账户对比.rar

234.95 KB, 下载次数: 25

账户对比

TA的精华主题

TA的得分主题

发表于 2011-3-11 09:08 | 显示全部楼层
原帖由 xmyjk 于 2011-3-11 01:14 发表
谢谢ah2005的指导:
出现问题的最大原因你说对了,没有加上清除COOKIE,DeleteUrlCacheEntry URL

增加API 引用wininet.dll的DeleteUrlCacheEntry函数去清楚缓存
修正后的代码如下,excel见附件:
Option Expli ...

呵呵,最近在研究抓包。

TA的精华主题

TA的得分主题

发表于 2011-3-11 09:09 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
xmyjk 兄弟真是我的偶像啊。
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-12-12 07:47 , Processed in 0.055144 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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