def get_balance(self, uid): html = safe_get(self.balance_url, headers=self.headers, cookies=self.cookies).content results = safe_xpath(html, ["//font[@color='#FF0000']"]) return results[0]
def _get_login_params(self): xp = "/html/body/form/input[%s]/@name" res = safe_get(self.index_url, headers=self.headers) html = res.content page = etree.HTML(html) param1 = page.xpath(xp % 1)[0] param2 = page.xpath(xp % 2)[0] return {"param1": param1, "param2": param2, "cookies": res.cookies}
def get_checkout_book(self, uid): self.init_from_redis(uid, only_cookies=True) res = safe_get(self.checkout_book_url, headers=self.headers, cookies=self.cookies) html = res.content.decode("utf-8") checkout_books = parse_standard_table(html, class_name="table_line", pure=True) return checkout_books
def search(self, keyword): _url = self.opac_url + "search_adv_result.php?sType0=any&q0=%s&with_ebook=&page=%s" url = _url % (keyword, 1) html = safe_get(url, headers=self.headers).content.decode("utf-8") page = etree.HTML(html) books_num = int( page.xpath(u"//div[@class='box_bgcolor']/font[last()]")[0].text) current_page = 1 books = [] url_code = [] while True: books.extend( parse_standard_table(html, "result_content", pure=True)) url_code.extend(safe_re('marc_no=(.*)"', html)) current_page += 1 if current_page > math.ceil(books_num / 20): break url = _url % (keyword, current_page) html = safe_get(url, headers=self.headers).content.decode("utf-8") return books, url_code
def get_consume(self): dates = self.cal_date() data = { "opertype": "query", "startDate": dates[1], "endDate": dates[0], "input": "查询" } index = 1 consume = [] last_count = 0 while True: if index == 1: html = safe_post(self.consume_url, data=data, headers=self.headers, cookies=self.cookies) index += 1 else: html = safe_get(self.consume_url + "?opertype=page&page=%s" % index, headers=self.headers, cookies=self.cookies) index += 1 html = html.content.decode("utf-8") consume.extend(parse_standard_table(html, pure=True)) count = len(consume) if count < 10 or (last_count != 10 and last_count == count): break else: last_count = count return consume
def get_captcha(self, cookies): res = safe_get(self.captcha_url, cookies=cookies) cookies = res.cookies return {"captcha": res.content, "cookies": cookies}
def get_captcha(self): res = safe_get(self.captcha_url + str(random.random()), stream=True) cookies = res.cookies return {"cookies": cookies, "captcha": res.content}
def get_book_detail(self, marc_no): url = self.opac_url + "item.php?marc_no=" + marc_no html = safe_get(url, headers=self.headers).content.decode("utf-8") remain_books = parse_standard_table(html, "item", pure=True) return remain_books