Python渲染后的网页简单 抓取 分析 提取 示例,自用笔记,其它人有可能不明白我是要做什么,呵呵

import time
from datetime import datetime

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

# from selenium.webdriver.chrome.service import Service

chrome_options = webdriver.ChromeOptions()

chrome_options.add_argument('--headless')  # 无界面模式
browser = webdriver.Chrome(chrome_options=chrome_options)

i = 1
while i < 3:
    try:
        browser.get(
            'https://ezil.me/personal_stats?wallet=你的钱包地址&coin=eth')
        # print(browser.current_url)
        # print(browser.page_source)
        now = datetime.now()
        str_time = str(now.strftime("%Y-%m-%d,%H:%M:%S"))

        txt1 = browser.find_elements_by_css_selector('.ezil-wb0bqw')
        num1 = str_time + ',' + txt1[0].text

        txt2 = browser.find_elements_by_css_selector('.ezil-1n3mmjs')
        num2 = num1 + ',' + txt2[2].text
        print(num2)
        with  open('c:\ezil.txt', 'a+') as f:
            f.write(num2+'\n')
            f.close()

    finally:
        #i += 1
        time.sleep(120)
browser.quit()

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注

35 − = 33