Script for ChaoXing

Get questions from website

from auto_everything.web import Selenium
from auto_everything.base import IO
import json
import os

my_selenium = Selenium("https://google.com", headless=False)
d = my_selenium.driver

problems = []

for file_name in [name for name in os.listdir(".") if ".html" in name]:
    d.get(f"file:///home/yingshaoxo/Documents/Fucking%20Document/{file_name}")

    xpath = """//*[@id="ZyBottom"]//div[contains(@class, 'TiMu')]"""
    elements = my_selenium.wait_until_exists(xpath)

    for block in elements:
        title = ""
        choices = ""

        title = block.find_elements_by_class_name("Zy_TItle")[0].find_element_by_class_name("clearfix").text
        print(title)
        try: 
            choices = "\n".join([one.find_element_by_tag_name("a").text.replace("\n", "") for one in block.find_elements_by_tag_name("li")])
            print(choices)
        except Exception as e:
            print(e)
        print('--'*10)

        problem = {
                "title": title,
                "choices": choices
        }
        problems.append(problem)

d.quit()
io = IO()
text = json.dumps(problems)
io.write("4.json", text)

Generate txt file

Add them all togather

Last updated

Was this helpful?