"'
!/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()
"'
网友评论