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


Python Tag.findAll方法代码示例

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


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

示例1: get_buy_orders_from_node

# 需要导入模块: from bs4 import Tag [as 别名]
# 或者: from bs4.Tag import findAll [as 别名]
def get_buy_orders_from_node(node: Tag) -> dict:
    buy_orders_raw = node.findAll("div", {"id": re.compile('mybuyorder_\\d+')})
    buy_orders_dict = {}
    for order in buy_orders_raw:
        qnt_price_raw = order.select("span[class=market_listing_price]")[0].text.split("@")
        order = {
            "order_id": order.attrs["id"].replace("mybuyorder_", ""),
            "quantity": int(qnt_price_raw[0].strip()),
            "price": qnt_price_raw[1].strip(),
            "item_name": order.a.text
        }
        buy_orders_dict[order["order_id"]] = order
    return buy_orders_dict
开发者ID:bukson,项目名称:steampy,代码行数:15,代码来源:utils.py

示例2: get_sell_listings_from_node

# 需要导入模块: from bs4 import Tag [as 别名]
# 或者: from bs4.Tag import findAll [as 别名]
def get_sell_listings_from_node(node: Tag) -> dict:
    sell_listings_raw = node.findAll("div", {"id": re.compile('mylisting_\d+')})
    sell_listings_dict = {}
    for listing_raw in sell_listings_raw:
        spans = listing_raw.select("span[title]")
        listing = {
            "listing_id": listing_raw.attrs["id"].replace("mylisting_", ""),
            "buyer_pay": spans[0].text.strip(),
            "you_receive": spans[1].text.strip()[1:-1],
            "created_on": listing_raw.findAll("div", {"class": "market_listing_listed_date"})[0].text.strip(),
            "need_confirmation": False
        }
        sell_listings_dict[listing["listing_id"]] = listing
    return sell_listings_dict
开发者ID:bukson,项目名称:steampy,代码行数:16,代码来源:utils.py

示例3: get_details

# 需要导入模块: from bs4 import Tag [as 别名]
# 或者: from bs4.Tag import findAll [as 别名]
def get_details(soup):
    categories = []
    all_details = {}
    details = Tag(name="table")
    details_css = [
        ("id", "productDetailsTable"),
        ("id","detail-bullets"),
        ("id","detailBullets")
    ]

    for row in details_css:
        key, val = row
        tag = soup.find(**{key:val})
        if tag:
            details = tag
            break

    for t in details.findAll("li"):
        text = t.text.strip()
        colon_pos = text.find(":")
        attr = text[:colon_pos].strip()
        val = text[colon_pos+1:].strip()
        if t.find("a"):
            remove_text = t.find("a").text
            val = val.replace(remove_text,"").replace("()","").strip()
        # if attr == "Shipping Weight":
        #     break
        if attr == "Average Customer Review":
            attr = "Reviews"
            try:
                val = re.search(r'\d customer review', val).group().strip()
                val = val.replace(" customer review", "")
            except:
                val = ""
                pass
        if attr == "Amazon Best Sellers Rank":
            cat_list = re.findall(categories_pattern, val)
            if cat_list:
                categories = [cat.replace(" in ","") for cat in cat_list]
            val = clean_string(val)
            a = re.search(r'#.+?\d ', val)
            a = a.group().replace(" ","").replace("#","").replace(",","")
            val = a
        all_details[attr] = val
    return all_details, categories
开发者ID:saurabh3949,项目名称:AmzGlass,代码行数:47,代码来源:amz_spider.py


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