import requests
from bs4 import BeautifulSoup


def get_next_page_doc_url_set(author_name,page_num,unit_name):
    """
    this function support the function:
    def get_doc_url_set(author_name,unit_name):
    get urls of specified page.
    
    Args:
        author_name: author's name
        page_num: specified page number
        unit_name: author's unit name
        
    Return:
        return set of doc urls  
    """
    headers = {
        "Host":"yuanjian.cnki.com.cn",
        "Connection":"keep-alive",
        "Content-Length":"473",
        "Accept":"text/html, */*; q=0.01",
        "Origin":"http://yuanjian.cnki.com.cn",
        "X-Requested-With":"XMLHttpRequest",
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36",
        "DNT":"1",
        "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
        "Referer":"http://yuanjian.cnki.com.cn/Search/Result",
        "Accept-Encoding":"gzip, deflate",
        "Accept-Language":"zh-CN,zh;q=0.9,en;q=0.8"
    }

    cookies = {
        "UM_distinctid":"168ae2b533519-0c21eda9d60a5f-57b143a-ea600-168ae2b533827",
    "KEYWORD":"%E5%BC%A0%E4%B9%85%E7%8F%8D%24%E7%89%9B%E4%B8%BD%E6%85%A7%24%E7%9F%AD%E5%B0%8F%E8%8A%BD%E5%AD%A2%E6%9D%86%E8%8F%8C%E8%A1%A8%E8%BE%BE%E7%B3%BB%E7%BB%9F%E7%9A%84%E4%BC%98%E5%8C%96%E7%A0%94%E7%A9%B6",
    "SID":"110105",
    "CNZZDATA1257838124":"249878561-1549106680-%7C1549701224"
    }

    base_url = "http://yuanjian.cnki.net/Search/Result"

    data = {
        "searchType":"MulityTermsSearch",
        "Author":author_name,
        "ParamIsNullOrEmpty":"true",
        "Islegal":"false",
        "Order":"1",
        "Page":page_num,
        "Unit":unit_name
    }

    r = requests.post(base_url,cookies = cookies,headers = headers,data = data)

    bs = BeautifulSoup(r.text,"html.parser")
    doc_url_set = [item["href"] for item in bs.find_all("a",{"target":"_blank","class":"left"})]
    
    return doc_url_set