def _get_contacts(self): self._headers['Cookie'] = self.task.cookie contacturl = 'https://mail.tom.com/webmail/contact/querycontact.action' formdata = {'type': 'searchContacts', 'contactname': ''} try: # r = requests.post(contacturl, headers=self._headers, data=formdata) html = self._ha.getstring( contacturl, req_data="type=searchContacts&contactname=", headers=""" Accept: application/json, text/javascript, */*; q=0.01 Accept-Encoding: gzip, deflate Accept-Language: en-US,en;q=0.9 Cache-Control: no-cache Connection: keep-alive Content-Length: 32 Content-Type: application/x-www-form-urlencoded Origin: https://mail.tom.com Pragma: no-cache Referer: https://mail.tom.com/webmail/main/index.action Sec-Fetch-Dest: empty Sec-Fetch-Mode: cors Sec-Fetch-Site: same-origin User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 X-Requested-With: XMLHttpRequest""") condata = json.loads(html).get('result', {}) if len(condata) == 0: return contact = CONTACT(self._clientid, self.task, self.task.apptype) for el in condata: eldict = {k: v for k, v in el.items() if v is not None} contactid = eldict.get('contactId') if contactid is not None: contact_one = CONTACT_ONE(self._userid, contactid, self.task, self.task.apptype) contact_one.nickname = eldict.get('contactName') contact_one.email = eldict.get('contactEmail') contact_one.append_details(eldict) contact.append_innerdata(contact_one) if contact.innerdata_len == 0: return else: yield contact except Exception: self._logger.error("Get contact error, err: {}".format( traceback.format_exc())) return
def __get_contacts(self, groupid): sid = self._get_cookie_sid() if sid is None: self._logger.error("Cannot get sid from cookie") return cguid = self._get_cookie_cguid() url = 'https://smsrebuild1.mail.10086.cn/addrsvr/GetContactsList?' \ 'sid={}&formattype=json&&comefrom=54&cguid={}'.format(sid, cguid) payload = '<object>\r\n <string name="GroupId">{}</string>\r\n <string name="Keyword" />\r\n ' \ '<string name="Letter">All</string>\r\n <string name="Filter" />\r\n ' \ '<string name="Sort">name</string>\r\n <string name="SortType" />\r\n ' \ ' <string name="Start">0</string>\r\n <string name="End">1000</string>\r\n' \ '</object>'.format(groupid) payload = payload.encode('ascii') headers = { 'accept': "*/*", 'accept-encoding': "gzip, deflate, br", 'accept-language': "zh-CN,zh;q=0.9,en;q=0.8", 'cache-control': "no-cache,no-cache", 'content-length': "290", 'Content-Type': "text/xml", 'cookie': self.task.cookie, 'origin': "https://smsrebuild1.mail.10086.cn", 'pragma': "no-cache", 'referer': "https://smsrebuild1.mail.10086.cn//proxy.htm", 'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/70.0.3538.102 Safari/537.36", } try: response = requests.request("POST", url, data=payload, headers=headers) res_json = json.loads(response.text) if res_json.get('code') == "S_OK": for con in res_json.get('var').get('list'): contactid = con.get('serialId') if contactid is not None: contact_one = CONTACT_ONE(self._userid, contactid, self.task, self.task.apptype) contact_one.nickname = con.get('name') contact_one.email = con.get('email') if con.get('mobile' ) is not None and con.get('mobile') != '': contact_one.phone = con.get('mobile') contact_one.append_details(con) yield contact_one except Exception as err: self._logger.error("Get a contact error, err: {}".format(err)) return