zoukankan      html  css  js  c++  java
  • 爬取网易某只股票2017-01到2018-01的数据

    import urllib.request
    import re
    import urllib
    import csv
    from selenium import webdriver
    from lxml import  etree
    import requests
    x=0
    header=['日期','开盘价','最高价','最低价','收盘价','涨跌额','涨跌幅','成交量','成交金额','振幅','换手率']
    with open('C:\Users\lenovo\Desktop\mmm.csv', 'a+', newline='', encoding='utf-8') as f:
        writer = csv.writer(f)
        writer.writerow(header)
    for i in range(2017,2019):
       url="http://quotes.money.163.com/trade/lsjysj_601939.html?year={}&season=".format(i)
       headers={ 'User-Agent':'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'}
       for k in range(1,5):
           ur=url+str(k)
           response=requests.get(ur,headers)
           html=etree.HTML(response.text)
           img=html.xpath('//tr[@class=""]/td')
           ok=html.xpath('//tr[@class="dbrow"]/td')
           x=x+1
           if x==6:
               break
           for i in range(len(img)-11,-1,-11):
               if img[i].text=='2018-02-01'or ok[i-11].text=='2018-02-01':
                   break
               data=list(img[j].text for j in range(i,i+11))
               data2 = list(ok[j-11].text for j in range(i, i + 11))
               with open('C:\Users\lenovo\Desktop\mmm.csv', 'a+', newline='', encoding='utf-8') as f:
                   writer = csv.writer(f)
                   writer.writerow(data)
                   writer.writerow(data2)
  • 相关阅读:
    删除字符串前后的空格
    Python中定义“私有”成员变量和成员函数
    linux 线程
    进程虚拟内存模型
    守护进程
    FIFO
    linux 中的 wait 函数和 waitpid 函数
    孤儿进程和僵尸进程
    linux 中的 exec 函数族
    linux中的fork函数
  • 原文地址:https://www.cnblogs.com/persistence-ok/p/11452305.html
Copyright © 2011-2022 走看看