本文整理汇总了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
示例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
示例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