码迷,mamicode.com
首页 > 编程语言 > 详细

Python 爬虫实例(8)—— 爬取 动态页面

时间:2018-01-08 14:53:34      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:alt   res   imp   margin   爬虫   log   python   设置   port   

今天使用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)

 

Python 爬虫实例(8)—— 爬取 动态页面

标签:alt   res   imp   margin   爬虫   log   python   设置   port   

原文地址:https://www.cnblogs.com/xuchunlin/p/8242231.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!