三个小问题

zydscaline 2011-09-28 05:48:52
第一,使用PAMIE 3.0时怎么取得IE的源码?

第二,怎么判断页面中某按钮存在并点击?用findElement?吗?

第三,怎么判断源码中包含某中文:如“新闻”?
...全文
208 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
zydscaline 2011-09-30
  • 打赏
  • 举报
回复
print ie._ie :出错
in __str__
return str(self.__call__())
UnicodeEncodeError: 'ascii' codec can't encode characters in position 14-18: ordinal not in range(128)

print ie._ie.document 正常,打印出:
[object]

print ie._ie.Document.GetElementsByTagName('head') 出错:
in __call__
return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None)
com_error: (-2147024891, '\xbe\xdc\xbe\xf8\xb7\xc3\xce\xca\xa1\xa3', None, None)


print ie._ie.Document.GetElementsByTagName 出错:
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
print ie._ie.Document.GetElementsByTagName
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 197, in __str__
return str(self.__call__())
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 182, in __call__
return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None)
com_error: (-2147024891, '\xbe\xdc\xbe\xf8\xb7\xc3\xce\xca\xa1\xa3', None, None)
zydscaline 2011-09-29
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 iambic 的回复:]
你这些问题不是都解决过吗?难道上次发帖的不是你?
[/Quote]问题有些小的变化,问题一我用ie.outerHTML取的源码是不含表头的,我想要全的源码。
判断页面中某按钮存在并点击我用findElement不知是菜了还是错了,不会,就想取IE的源码后,用正则,但正则模仿PERL的却不行,那位大虾在这儿写个?
iambic 2011-09-29
  • 打赏
  • 举报
回复
你把ie._ie.Document.DocumentElement.outerHTML[:100]和ie._ie.Document.GetElementsByTagName('head')的结果贴出来看下。
zydscaline 2011-09-29
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 iambic 的回复:]
试下:

Python code
ie._ie.Document.DocumentElement.outerHTML

如果要拿html head,可以:

Python code
ie._ie.Document.GetElementsByTagName('head')[0].outerHTML
[/Quote]ie._ie.Document.DocumentElement.outerHTML取出的源码汉字全变成十六进制的了!


ie._ie.Document.GetElementsByTagName('head')[0].outerHTML则是出错:Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
ie._ie.Document.GetElementsByTagName('head')[0].outerHTML
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 182, in __call__
return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None)
com_error: (-2147024891, '\xbe\xdc\xbe\xf8\xb7\xc3\xce\xca\xa1\xa3', None, None)

iambic 2011-09-29
  • 打赏
  • 举报
回复
试下:
ie._ie.Document.DocumentElement.outerHTML

如果要拿html head,可以:
ie._ie.Document.GetElementsByTagName('head')[0].outerHTML
zydscaline 2011-09-29
  • 打赏
  • 举报
回复
以百义为例,PAMIE的OUTERHTML出的源码和直接查看的源码之间的差别是:
百度的表头
<!doctype html><html><head><meta http-equiv="Content-Type" content="text/html;charset=gb2312"><title>百度一下,你就知道</title><style>html{overflow-y:auto}body{font:12px arial;text-align:center;background:#fff}body,p,form,ul,li{margin:0;padding:0;list-style:none}body,form,#fm{position:relative}td{text-align:left}img{border:0}a{color:#00c}a:active{color:#f60}#u{padding:7px 10px 3px 0;text-align:right}#m{width:680px;margin:0 auto}#nv{font-size:16px;margin:0 0 4px;text-align:left;text-indent:117px}#nv a,#nv b,.btn,#lk{font-size:14px}#fm{padding-left:90px;text-align:left}#kw{width:404px;height:22px;padding:4px 7px;padding:6px 7px 2px\9;font:16px arial;background:url(http://www.baidu.com/img/i-1.0.0.png) no-repeat -304px 0;_background-attachment:fixed;border:1px solid #cdcdcd;border-color:#9a9a9a #cdcdcd #cdcdcd #9a9a9a;vertical-align:top}.btn{width:95px;height:32px;padding:0;padding-top:2px\9;border:0;background:#ddd url(http://www.baidu.com/img/i-1.0.0.png) no-repeat;cursor:pointer}.btn_h{background-position:-100px 0}#kw,.btn_wr{margin:0 5px 0 0}.btn_wr{width:97px;height:34px;display:inline-block;background:url(http://www.baidu.com/img/i-1.0.0.png) no-repeat -202px 0;_top:1px;*position:relative}#lk{margin:33px 0}#lk span{font:14px "宋体"}#lm{height:60px}#lh{margin:16px 0 5px;word-spacing:3px}#mCon{height:18px;line-height:18px;position:absolute;right:7px;top:8px;top:10px\9;cursor:pointer;padding:0 18px 0 0;background:url(http://www.baidu.com/img/bg-1.0.0.gif) no-repeat right -134px;background-position:right -136px\9}#mCon span{color:#00c;cursor:default;display:block}#mCon .hw{text-decoration:underline;cursor:pointer}#mMenu{width:56px;border:1px solid #9a99ff;list-style:none;position:absolute;right:7px;top:28px;display:none;background:#fff}#mMenu a{width:100%;height:100%;display:block;line-height:22px;text-indent:6px;text-decoration:none}#mMenu a:hover{background:#d9e1f6}#mMenu .ln{height:1px;background:#ccf;overflow:hidden;margin:2px;font-size:1px;line-height:1px}#cp,#cp a{color:#77c}#sh{display:none;behavior:url(#default#homepage)}</style>
</head>
这是PAMIE的OUTERHTML提不出来的,

另表尾:直接查看是:
<script type="text/javascript" src="http://www.baidu.com/cache/hps/js/hps-1.1.1.js"></script>
</html><!--0c82163570518b31-->

用PAMIE的OUTERHTML查看是:
<SCRIPT src="http://www.baidu.com/js/bdsug.js?v=1.0.3.0"></SCRIPT>



<SCRIPT src="http://www.baidu.com/cache/hps/js/hps-1.1.1.js" type=text/javascript></SCRIPT>

<SPAN style="DISPLAY: none; BEHAVIOR: url(#default#homepage)"></SPAN><!--0c82163570518b31--></BODY>

它们之间的差别好象就是这些,别的差别人没看出来
iambic 2011-09-29
  • 打赏
  • 举报
回复
什么叫不含“表头”?你最好找出具体的网页,和你需要的具体内容。不然的话别人再写一个可能还是没有你要的什么表头。
按钮也需要具体的网页和具体的按钮,因为按钮的种类有很多。有<input>有<button>有<a>还有图片的。不同的按钮可能方式不一样。
iambic 2011-09-29
  • 打赏
  • 举报
回复
奇怪。你依次打印出ie._ie,ie._ie.Document,ie._ie.Document.GetElementsByTagName试试。
PS:你的ie没关吧?
zydscaline 2011-09-29
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 iambic 的回复:]
可能你还没搞清楚下面的区别……

Python code
>>> print '中文'
中文
>>> '中文'
'\xd6\xd0\xce\xc4'
>>> print '\xd6\xd0\xce\xc4'
中文
>>> print repr('\xd6\xd0\xce\xc4')
'\xd6\xd0\xce\xc4'



我7楼问的是ie._ie.Document.……
[/Quote]ie._ie.Document.GetElementsByTagName('head'),的提示是:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
ie._ie.Document.GetElementsByTagName('head')
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 182, in __call__
return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None)
com_error: (-2147024891, '\xbe\xdc\xbe\xf8\xb7\xc3\xce\xca\xa1\xa3', None, None)
iambic 2011-09-29
  • 打赏
  • 举报
回复
可能你还没搞清楚下面的区别……
>>> print '中文'
中文
>>> '中文'
'\xd6\xd0\xce\xc4'
>>> print '\xd6\xd0\xce\xc4'
中文
>>> print repr('\xd6\xd0\xce\xc4')
'\xd6\xd0\xce\xc4'


我7楼问的是ie._ie.Document.GetElementsByTagName('head'),不是ie._ie.Document.GetElementsByTagName('head')[0].outerHTML。
zydscaline 2011-09-29
  • 打赏
  • 举报
回复
晕,print ie._ie.Document.DocumentElement.outerHTML是正确的源码,而直接ie._ie.Document.DocumentElement.outerHTML出来的源码汉字都成十六进制了


ie._ie.Document.GetElementsByTagName('head')[0].outerHTML则是出错:Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
ie._ie.Document.GetElementsByTagName('head')[0].outerHTML
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 182, in __call__
return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None)
com_error: (-2147024891, '\xbe\xdc\xbe\xf8\xb7\xc3\xce\xca\xa1\xa3', None, None)
iambic 2011-09-28
  • 打赏
  • 举报
回复
你这些问题不是都解决过吗?难道上次发帖的不是你?

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧