def process_item(): try: cookie = 'OZ_1U_2061=vid=v84a8a99a17f61.0&ctime=1481280351<ime=1481280207; otherx=e%3D1%26p%3D*%26s%3D0%26c%3D0%26f%3D0%26g%3D0%26t%3D0; mbk=5dd5b762527e7c53; _tb_token_=ee737183193e6; ck1=; uc1=cookie14=UoW%2BuvgMtNhjKA%3D%3D&lng=zh_CN&cookie16=U%2BGCWk%2F74Mx5tgzv3dWpnhjPaQ%3D%3D&existShop=false&cookie21=URm48syIYn73&tag=3&cookie15=UIHiLt3xD8xYTw%3D%3D&pas=0; uc3=sg2=Wqbxb6LyHC3oJzu6qXhfKTl7%2FAp31ETbn2A2Kj%2FuE90%3D&nk2=F5NO4MKvNg%3D%3D&id2=UNGQXF%2FfFY8%3D&vt3=F8dARVK2A0Q653XIlwM%3D&lg2=U%2BGCWk%2F75gdr5Q%3D%3D; lgc=teemimi; tracknick=teemimi; cookie2=1c98dde86727cf811a84e96da0b57801; cookie1=UNICLQDxGeiUdu2e8mzQbAdAJ72nNq7WNSx7YehUHhE%3D; unb=31634811; t=c1a07a395b20ebf0a0e52a6d601ffb71; skt=a7ef272f517551b6; _nk_=teemimi; _l_g_=Ug%3D%3D; cookie17=UNGQXF%2FfFY8%3D; hng=; uss=B0E3dfs1Nf2o7S9bOHn9v86329LgubJG5ximIyCeMFRZ%2Bv0IqJTrCxIsuZc%3D; login=true; cna=EbDKEIIrPBcCAXhVUl24UDEN; isg=AiQkkA1jIGPJ81R1qn75z7u09SIjs1NNPRl-0T5Fj--y6cazZs0Yt1of3_aL; l=AuHh2Murc/6E3948EdyV7MR4caf7sVWA' headers.update( Referer='https://detail.tmall.com/item.htm?id=522189908497') headers.update(cookie=cookie) resp = http( 'GET', 'https://bar.tmall.com/cueAssetMsg.htm?sellerId=515369883&itemId=522189908497&callback=jsonp692&_input_charset=UTF-8', headers) # resp,num=re.subn(r'(process_comment\()({.*})(\));',r'\1%s\2%s\3'%('\'','\''),resp) print resp except Exception as e: print_err()
def process_item(page=1): try: resp = http( 'GET', 'http://money.finance.sina.com.cn/quotes_service/api/jsonp_v2.php/IO.XSRV2.CallbackList[\'y2PhvJWEK4sZBTJW\']/StatisticsService.getVolumeReduceConList?page=%d&num=50&sort=day_con&asc=0&node=adr_hk' % page) # resp,num=re.subn(r'(process_comment\()({.*})(\));',r'\1%s\2%s\3'%('\'','\''),resp) # print resp m = re.match( ur'^(IO\.XSRV2\.CallbackList\[\'y2PhvJWEK4sZBTJW\'\]\()(\[\{.*\}\])(\))$', resp) if m: resp = m.group(2) process_sl(resp.decode('gbk')) else: print 'error in process_item ' except Exception as e: print_err()
def followed(self, dstuid): followedurl = "http://weibo.com/aj/f/followed?ajwvr=6&__rnd=%s" % int( time.time()) data = { 'uid': '%s' % dstuid, 'rank': '0', 'location': 'mblog', '_t': '0', 'extra': '', 'f': '1', 'oid': '%s' % self.uid, 'nogroup': 'false', 'challenge_uids': '', 'check_challenge_value': '', 'location': 'home', 'refer_sort': 'card', 'refer_flag': 'followed', 'refer_flag': '0000020001_', 'refer_lflag': '', 'template': '1', } # headers['set-cookie'] = resp.headers['set-cookie'] headers.update(Referer='http://weibo.com/u/' + self.uid + '?topnav=1&wv=5') result = http('POST', followedurl, headers, **data) default_logger.info( '-----------------result-----------------------------------') default_logger.info(result) default_logger.info( '----------------------------------------------------') result = json.loads(result) if result['code'] == '100000': return True else: default_logger.info( '-----------------fail msg-----------------------------------') default_logger.info(result['msg']) default_logger.info( '----------------------------------------------------') return False
def get_ip(self): print 'ddd' sd = http('GET', 'http://1212.ip138.com/ic.asp', headers=headers) print 'ddd,lll' print 'dddd88ss_%s' % (sd)
def read_jingxuan_for_json(path): data = xlrd.open_workbook(path) #打开文件 table = data.sheets()[0] #通过索引顺序获取 # table = data.sheet_by_index(0) #通过索引顺序获取 # table = data.sheet_by_name(u'Sheet1')#通过名称获取 # 获取整行和整列的值(数组) # table.row_values(i) # table.col_values(i) # 获取行数和列数 nrows = table.nrows ncols = table.ncols print nrows, ncols # word={} # 循环行列表数据 j = {} d = { 'fenlei': 0, 'shop': 1, 'open': 2, 'id': 3, 'name': 4, 'item_url': 5, 'image': 6, 'price': 7, 'quan': 10, 'final_price': 11, 'start': 14, 'end': 15, 'link': 16 } for r in xrange(1, nrows): jinxuan = {} for k, v in d.items(): col = table.cell(r, v).value link = table.hyperlink_map.get((r, v)) # link=table.cell(r,c).Hyperlinks.Item(1).Address print col, link.url_or_path if link else None if k == 'fenlei': simple = col.split('/', 1)[0] if len(simple) > 4: jinxuan.update({'simple': ''}) else: jinxuan.update({'simple': simple}) if k == 'id': id_col = col jinxuan.update({k: link.url_or_path if link else col}) kw = {'timeout': 30, 'id': id_col} request_url = 'https://detail.tmall.com/item.htm' fenlei = j.get(jinxuan.get('fenlei')) if fenlei: shop = fenlei.get(jinxuan.get('shop')) if shop: shop_link = shop.get('url') if not shop_link: r = http('GET', request_url, headers, **kw) # sel=Selector(text=r).xpath('/html/head/link[@rel="canonical"]/@href') shop_link, shop_age = get_shop_parameter( r, jinxuan.get('open')) else: shop_age = shop.get('age') shop_list = shop.get('list') if shop_list: shop_list.append(jinxuan) else: shop_list = [jinxuan] shop = { 'url': shop_link, 'open': jinxuan.get('open'), 'age': shop_age, 'list': shop_list } else: r = http('GET', request_url, headers, **kw) # sel=Selector(text=r).xpath('/html/head/link[@rel="canonical"]/@href') shop_link, shop_age = get_shop_parameter( r, jinxuan.get('open')) shop = { 'list': [jinxuan], 'url': shop_link, 'open': jinxuan.get('open'), 'age': shop_age } fenlei.update({jinxuan.get('shop'): shop}) j.update({jinxuan.get('fenlei'): fenlei}) else: # print jinxuan.get('item_url'),'-----------------------' r = http('GET', request_url, headers, **kw) # print r,'-----------------------' # sel=Selector(text=r).xpath('/html/head/link[@rel="canonical"]/@href') shop_link, shop_age = get_shop_parameter(r, jinxuan.get('open')) j.update({ jinxuan.get('fenlei'): { jinxuan.get('shop'): { 'list': [jinxuan], 'url': shop_link, 'age': shop_age, 'open': jinxuan.get('open') } } }) json.dump(j, open('%s/%s' % (JINXUAN_DIR, 'jinxuan.json'), 'w'))
def send_blog(self, blog_title, blog_body, blog_class, tag, vtoken, blog_vote=None): vote = { 'voteId': '', 'blogVote': 'yes', 'voteType': '1', 'voteTitle': '我 是 一 个 中 国 人 哈', 'voteData[]': '1111', 'voteData[]': '2222', 'voteData[]': '3333', 'voteData[]': '4444', 'voteData[]': '', 'rad': 'on', 'votePos': '0', 'voteYear': '2016', 'voteMonth': '8', 'voteDay': '5', 'voteHour': '10', } assoc = { 'assoc_article': '3d837c2c0102whmy,3d837c2c0100c4wm', 'assoc_style': '1', 'assoc_article_data': '', } kw = { 'ptype': '', 'teams': '', 'worldcuptags': '', 'album': '', 'album_cite': '', 'blog_id': '', 'is_album': '0', 'old365': '0', 'stag': '', 'sno': '', 'book_worksid': '', 'channel_id': '', 'url': '', 'channel': '', 'newsid': '', 'fromuid': '', 'wid': '', 'articletj': '', 'vtoken': 'vtoken', 'is_media': '0', 'is_stock': '0', 'is_tpl': '0', 'assoc_article': '', 'assoc_style': '1', 'assoc_article_data': '', 'article_BGM': '', 'xRankStatus': '', 'commentGlobalSwitch': '', 'commenthideGlobalSwitch': '', 'articleStatus_preview': '1', 'source': '', 'topic_id': '0', 'topic_channel': '0', 'topic_more': '', 'utf8': '1', 'conlen': '15', 'date_pub': '2016-06-04', 'time': '22:16:37', 'new_time': '', 'isTimed': '0', 'immediatepub': '0', 'blog_title': 'this is title9', 'blog_body': 'this is content9', 'blog_class': '2', 'tag': 'tag1,tag2,tag3,tag4,健康', 'x_cms_flag': '0', 'sina_sort_id': '117', } kw['blog_title'] = blog_title kw['blog_body'] = blog_body kw['blog_class'] = blog_class kw['date_pub'] = datetime.datetime.now().strftime('%Y-%m-%d') kw['time'] = datetime.datetime.now().strftime('%H:%M:%S') kw['tag'] = tag kw['vtoken'] = vtoken try: assoc_article = json.load(open( 'D:/mywork/tmall/assoc_user_%s.json' % u, 'r'), strict=False) except: assoc_article = None if assoc_article: assoc['assoc_article'] = ','.join(assoc_article) kw.update(**assoc) if blog_vote: kw.update(**blog_vote) headers.update( Referer= 'http://control.blog.sina.com.cn/admin/article/article_add.php') result = http( 'POST', 'http://control.blog.sina.com.cn/admin/article/article_post.php', headers, **kw) default_logger.info( '-----------------result-----------------------------------') default_logger.info(result) default_logger.info( '----------------------------------------------------') result = json.loads(result) if result['code'] == 'B06001': result_id = result['data'] if not assoc_article: assoc_article = [] assoc_article.insert(0, result_id) del assoc_article[10:] json.dump(assoc_article, open('D:/mywork/tmall/assoc_user_%s.json' % u, 'w'))