美文网首页
历史天气

历史天气

作者: 机会call | 来源:发表于2019-04-09 11:33 被阅读0次

    "'

    !/usr/bin/python

    -- coding: utf-8 --

    import requests
    from bs4 import BeautifulSoup
    from lxml import etree
    import numpy as np
    import pandas as pd
    import csv

    class Spider(object):

    def start_request(self):
        url= "https://www.baidutianqi.com/history/57016.htm"
        response = requests.get(url)
        html = etree.HTML(response.content.decode())
        Big_src= html.xpath('//div[@class="list2 clearfix"]/ul/li/a/@href')
        for bigsrc in Big_src:
            self.file_request(bigsrc)
    
    
    
    def file_request(self,bigsrc):
        response = requests.get(bigsrc)
        html = etree.HTML(response.content.decode())
        content= html.xpath('//tr/td/text()')
        for i in range(0,len(content),6):
            ones=content[i:i+6]
            with open('baoji.csv', 'a') as f:
                f.write(str(ones) + '\n')
    

    spider=Spider()
    spider.start_request()
    "'

    相关文章

      网友评论

          本文标题:历史天气

          本文链接:https://www.haomeiwen.com/subject/drcbiqtx.html