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)
  • 相关阅读:
    win7安装mysql解压缩版
    PCA原理
    通俗理解协方差
    python GIL
    yield理解
    python super 的正确理解
    python常见面试题
    python 的特殊方法 __str__和__repr__
    springMvc REST 请求和响应
    Math.Round 四舍五入问题 解惑 !
  • 原文地址:https://www.cnblogs.com/xuchunlin/p/8242231.html
Copyright © 2011-2022 走看看