当前位置: 首页>>代码示例>>Python>>正文


Python PyQuery.replace方法代码示例

本文整理汇总了Python中pyquery.pyquery.PyQuery.replace方法的典型用法代码示例。如果您正苦于以下问题:Python PyQuery.replace方法的具体用法?Python PyQuery.replace怎么用?Python PyQuery.replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyquery.pyquery.PyQuery的用法示例。


在下文中一共展示了PyQuery.replace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __getPageAllLink

# 需要导入模块: from pyquery.pyquery import PyQuery [as 别名]
# 或者: from pyquery.pyquery.PyQuery import replace [as 别名]
    def __getPageAllLink(self,p):        
#        if self.kind=="1":
#            lis=PyQuery(p)("div.qiuzu li")
#        elif self.kind=="2":
#            lis=PyQuery(p)("div.qiuzu li")
        if self.kind=="1" or self.kind=="2":
            lis=PyQuery(p)("div.house")
        else:
            lis=PyQuery(p)("div.qiuzu li")
        links=[]
        for li in lis:
#            if self.kind=="3":
#                tm=PyQuery(li)("p.time span").eq(1).text()
#                link=self.baseurl+PyQuery(li)("p.housetitle a").attr("href")
            if self.kind=="2" or self.kind=="1":
                tm=PyQuery(li)("p.time").text()
                tm=tm and tm.replace("个人","") or ""
                link=self.baseurl+PyQuery(li)("p.housetitle a").attr("href")
            else: 
                tm=PyQuery(li)("span.li5").text()
                link=self.baseurl+PyQuery(li)("span.li2 a").attr("href")
            if self.kind=="4": 
                if PyQuery(li)("span.li1").text()=="合租 ":
                    continue
#            tm=PyQuery(li)("span.li5").text()
#            link=self.baseurl+PyQuery(li)("span.li2 a").attr("href")
            #link=self.baseurl+PyQuery(li)("span.li2 a").attr("href")
#            print link
            if u"天" in tm:
                s=tm.find(u"天")
                tm=tm[:s]
                if int(tm)<8:
                    links.append(link)
                else:
                    break
            elif u"小时" in tm:
                links.append(link)
            elif u"分钟" in tm:
                links.append(link)
            else:
                continue
            if 1:#not checkPath(homepath,self.folder,link):
                LinkLog.info("%s|%s"%(self.kind,link))
                try:
                    getContent(link,self.citycode,self.kind)
                except Exception,e:print "ganji getContent Exception %s"%e
            time.sleep(int(self.st))
#            fetch_quere.put({"mod":"soufang","link":link,"citycode":self.citycode,"kind":self.kind})
#        self.clinks.extend(links)
       
        if self.kind=="1" or self.kind=="2":
            if len(links)!=30:
                return False
            else:
                return True
        else:
            if len(links)!=35:
                return False
            else:
                return True
开发者ID:ptphp,项目名称:PyLib,代码行数:62,代码来源:soufun.py

示例2: parse

# 需要导入模块: from pyquery.pyquery import PyQuery [as 别名]
# 或者: from pyquery.pyquery.PyQuery import replace [as 别名]
 async def parse(self, input_text, *k, **kk):
     logging.debug(input_text)
     html = PyQuery(await get_url_service.get_url_async(input_text))
     url = ""
     # logging.debug(html)
     if not url:
         jss = html("script[type='text/javascript']")
         for item in jss:
             text = PyQuery(item).text()
             # logging.debug(text)
             if "Q.PageInfo.playPageData = {" in text or \
                     "Q.PageInfo.playPageInfo = Q.PageInfo.playPageInfo || {" in text:
                 split_text = text.replace("\r", ""). \
                                  replace("\n", ""). \
                                  replace("Q.PageInfo.playPageData = {", ""). \
                                  replace("window.Q = window.Q || {};", ""). \
                                  replace("var Q = window.Q; Q.PageInfo = Q.PageInfo || {};", ""). \
                                  replace("Q.PageInfo.playPageInfo = Q.PageInfo.playPageInfo ||", ""). \
                                  strip(). \
                                  replace("albumData:", ""). \
                                  strip()[:-1].strip()
                 logging.debug(split_text)
                 try:
                     data = json.loads(split_text)
                     print(json.dumps(data))
                     if "mixinVideos" in data and type(data["mixinVideos"]) == list:
                         for item1 in data["mixinVideos"]:
                             if type(item1) == dict and 'crumbList' in item1 and type(item1['crumbList']) == list:
                                 for item2 in item1['crumbList']:
                                     if type(item2) == dict and 'level' in item2 and \
                                             item2['level'] == 3 and 'url' in item2:
                                         url = item2['url']
                                         if url and re.search(r"www.iqiyi.com/v_", url):
                                             url = None
                             if url:
                                 logging.debug(url)
                                 break
                     elif "albumUrl" in data and data["albumUrl"]:
                         url = "http:" + data["albumUrl"]
                         logging.debug(url)
                         break
                 except json.JSONDecodeError:
                     logging.exception("IQiYiVListParser Error")
             if url:
                 break
     if not url:
         ld_json = html("script[type='application/ld+json']")
         for item in ld_json:
             text = PyQuery(item).text().replace("\n", "").replace("\r", "")
             try:
                 data = json.loads(text)
                 if "itemListElement" in data and type(data["itemListElement"]) == list:
                     for item1 in data["itemListElement"]:
                         if type(item1) == dict and 'position' in item1 and \
                                 item1['position'] == 3 and 'item' in item1:
                             if type(item1['item']) == dict and '@id' in item1['item']:
                                 url = item1['item']['@id']
                                 if url and re.search(r"www.iqiyi.com/v_", url):
                                     url = None
                     if url:
                         logging.debug(url)
                         break
             except json.JSONDecodeError:
                 logging.exception("IQiYiVListParser Error")
             if url:
                 break
     if not url:
         data_info_list = PyQuery(html("h2.playList-title-txt"))
         for a in data_info_list.children('a'):
             a = PyQuery(a)
             url = a.attr("href")
             if url:
                 logging.debug(url)
                 break
     if not url:
         a = PyQuery(html("a[data-albumurlkey]"))
         url = a.attr("href")
         logging.debug(url)
     if url and re.search(r"www.iqiyi.com/v_", url):
         url = None
     if url:
         if str(url).startswith("//"):
             url = "http:" + str(url)
         logging.info("change %s to %s" % (input_text, url))
         return ReCallMainParseFunc(input_text=url, types="list")
开发者ID:wwqgtxx,项目名称:wwqLyParse,代码行数:87,代码来源:iqiyilistparser.py


注:本文中的pyquery.pyquery.PyQuery.replace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。