zoukankan      html  css  js  c++  java
  • 解决不支持cookie的手机访问wap(session)

    在wap解析器中,大量用到了session,为了解决有些手机不支持cookie的问题,使用java的Url重写方法response.encodeURL();

    由于我的wml或xhtml页面是动态通过xml+xslt解析生成的。。。所以我在最后解析的方法里加上response.encodeURL

    关键代码如下
    //replace form @action
    List list = objXmlOutput.selectNodes("//*[name()='form']/@action");
                    for (Iterator iter = list.iterator(); iter.hasNext();) {
                        Attribute attribute = (Attribute) iter.next();
                        attribute.setValue(response.encodeURL(attribute.getValue()));
                    }
                    //replace a @href
                    list = objXmlOutput.selectNodes("//*[name()='a']/@href");
                    for (Iterator iter = list.iterator(); iter.hasNext();) {
                        Attribute attribute = (Attribute) iter.next();
                        attribute.setValue(response.encodeURL(attribute.getValue()));
                    }
                    //replace option @onpick
                    list = objXmlOutput.selectNodes("//*[name()='option']/@onpick");
                    for (Iterator iter = list.iterator(); iter.hasNext();) {
                        Attribute attribute = (Attribute) iter.next();
                        attribute.setValue(response.encodeURL(attribute.getValue()));
                    }


            埃。。。用xpath这么久了,才发现   //a/@href  和 //*[name()='a']/@href  是有差别的 ,估计前者是只取第一个节点,后则匹配所有节点,不解 ,……


    开始有点讨厌Linux


  • 相关阅读:
    素数判定方法,方法持续更新...
    C++暂停黑窗口
    【python爬虫】scrapy入门6-生成多个spider
    【python爬虫】scrapy入门5--xpath等后面接正则
    python基础:list与string互转
    【python爬虫】scrapy实战1--百万微博任性采集
    【python爬虫】scrapy入门4--添加cookies
    【python爬虫】scrapy入门2--自定义item
    【python爬虫】scrapy入门1--环境搭建
    sklearn学习:为什么roc_auc_score()和auc()有不同的结果?
  • 原文地址:https://www.cnblogs.com/yesun/p/503402.html
Copyright © 2011-2022 走看看