Esempio n. 1
0
    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]
Esempio n. 2
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}
Esempio n. 3
0
 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
Esempio n. 4
0
    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
Esempio n. 5
0
    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
Esempio n. 6
0
 def get_captcha(self, cookies):
     res = safe_get(self.captcha_url, cookies=cookies)
     cookies = res.cookies
     return {"captcha": res.content, "cookies": cookies}
Esempio n. 7
0
 def get_captcha(self):
     res = safe_get(self.captcha_url + str(random.random()), stream=True)
     cookies = res.cookies
     return {"cookies": cookies, "captcha": res.content}
Esempio n. 8
0
 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