"whoPayShip": xpath("//input[@name='who_pay_ship']/@value"), "rootCatId": xpath("//input[@name='rootCatId']/@value"), "catagory": fields("exparams", search(r"category\=(.+?)&")), "at_bucketid": fields("exparams", search(r"at_bucketid\=(.+?)&")), "b2c_brand": fields("exparams", search(r"b2c_brand\=(.+?)&")), "at_autype": fields("exparams", search(r"at_autype\=(.+?)&")), "bucketId": search(r'bucketId:[\'"](\d+)[\'"]'), "skuPrice": ajax("initApi", dpath("['defaultModel']['itemPriceResultDO']['priceInfo']")), "brandId": fields("TShop.Setup", dpath("['itemDO']['brandId']")), "categoryId": fields("TShop.Setup", dpath("['itemDO']['categoryId']")), "quantity": fields("TShop.Setup", dpath("['itemDO']['quantity']")), "tradeList": ajax("oldDealRecords", dpath("['html'].encode('utf-8')")), "rateList": ajax("oldRateList", dpath("['rateDetail']['rateList']")), }, "result_filters": { "catagory": ("unquote", ("{result}",)), "at_bucketid": ("unquote", ("{result}",)), "at_autype": ("unquote", ("{result}",)), "brand": ("_unescape", ("{result}",)), "attrList": (None, "dict((k, v.strip(u' \xa0')) for k,v in result)"), }, } top_item = {"super": top_item_base, "template_target": {"B": top_tmallitem, "C": top_citem}} top_tmallitem = init_rules(top_tmallitem) top_citem = init_rules(top_citem) top_item = init_rules(top_item)
# encoding: utf8 from sasoup.baserules import xpath, xpaths, xpathz, search, dpath, base, addon, fields, which, next, ajaxurl, ajax, RespType from sasoup.baserules import init_rules rules = { 'url': 'http://www.etao.com', 'fields_rules': { 'feedList': xpaths("//div[@id='J_FeedList']//div[@id]", evalx="result"), }, 'result_rules': { 'feed': ( xpathz('feedList', xpath(".//h3[@class='feed-title']/a/@title", evalx="_strip(result)")), xpathz('feedList', xpath(".//h3[@class='feed-title']/a/strong/text()", evalx="_strip(result)")), xpathz('feedList', xpath(".//div[@class='feed-desc']/p/text()", evalx="_strip(result)")), ), 'cats': next( xpaths("//div[contains(@class,'J_PCMain')/li]", evalx="result"), xpath(".//h3/a/text()", evalx="result"), ), }, } rules = init_rules(rules)