zoukankan      html  css  js  c++  java
  • Python 爬虫实例(8)—— 爬取 动态页面

    今天使用python 和selenium爬取动态数据,主要是通过不停的更新页面,实现数据的爬取,要爬取的数据如下图

    源代码:

    #-*-coding:utf-8-*-
    import time
    from selenium import webdriver
    import os
    import re
    #引入chromedriver.exe
    chromedriver = "C:/Users/xuchunlin/AppData/Local/Google/Chrome/Application/chromedriver.exe"
    os.environ["webdriver.chrome.driver"] = chromedriver
    browser = webdriver.Chrome(chromedriver)
    
    #设置浏览器需要打开的url
    url = "https://www.jin10.com/"
    # 使用for循环不停的刷新页面,也可以每隔一段时间刷新页面
    for i in range(1,100000):
        browser.get(url)
        result= browser.page_source
        gold_price = ""
        gold_price_change = ""
        try:
            gold_price = re.findall('<div id="XAUUSD_B" class="jin-price_value" style=".*?">(.*?)</div>',result)[0]
            gold_price_change = re.findall('<div id="XAUUSD_P" class="jin-price_value" style=".*?">(.*?)</div>',result)[0]
        except:
            gold_pric = "------"
            gold_price_change = "------"
    
        print gold_price
        print gold_price_change
        time.sleep(1)
  • 相关阅读:
    安装 Cacti 监控
    增加yum源方式 安装升级 Mysql
    Yum
    Cacti 抓取数据方式 安装spine
    Linux 目录解析
    Linux 发行版本简述
    php 安装扩展插件实例-ftp.so
    Crontab 计划任务
    文本处理命令 cat more less cut wc sort uniq
    grep命令
  • 原文地址:https://www.cnblogs.com/xuchunlin/p/8242231.html
Copyright © 2011-2022 走看看