
import json
import ast
from all_connect import ConnectSpider
Con = ConnectSpider()
import ast
import gzip
import requests
from lxml import etree
from  amazon_params import py_ja3
from datetime import datetime
import re
from datetime import datetime
from collections import defaultdict
import json
import io
from multiprocessing import Pool
from multiprocessing import Queue
from multiprocessing import Process, Manager, Lock
import queue



# asins = Con.get_asin_html_06_asin()
# print(asins)


def decompress_bytes(input_bytes):
    if isinstance(input_bytes, str):
        input_bytes = ast.literal_eval(input_bytes)
    return gzip.decompress(input_bytes).decode('utf-8')

def execution_parse(asin_html):
    keywords_scraper_url_list = asin_html.split('||-||')
    asin_org = keywords_scraper_url_list[0]
    html_org = keywords_scraper_url_list[1]
    print(f'当前解析：{asin_org}')
    html_str = json.loads(html_org)
    html = decompress_bytes(html_str)
    filename = f"{asin_org}1.html"
    with open(filename, 'w', encoding='utf-8') as f:
        f.write(html)

def run():
    asin_html_pairs = Con.look_html()
    if asin_html_pairs:
        for asin_html in asin_html_pairs:
            execution_parse(asin_html)

    else:
        print("没有符合条件的数据需要处理")
        return

run()



