1. 程式人生 > >Pullword 分詞工具

Pullword 分詞工具

encoding .post Coding req with open 返回 con ali live

    def get_response(self, txt):
        """ 熱詞工具 """
        datas = []
        request_lists = []
        # 篩選文本
        with open(txt,r, encoding=utf8) as f:
            for line in f:
                data_one = line.strip()
                if data_one:
                    datas.append(data_one)
        url 
= http://www.pullword.com/process.php headers = { "Connection": "keep-alive", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0" } for data in datas: FromData = { source: data,
param1: 1, param2: 0 } try: response = requests.post(url, headers=headers, data=FromData) except: print("熱詞 {} 請求有誤...".format(data)) else: content = response.text content
= (content.split(SAMEORIGIN)[1]).strip() # 去除空格 contents = content.split(\r\n) # 獲取單詞list request_lists.extend(contents) # 將其合並 return request_lists # 返回list

Pullword 分詞工具