一.从网上爬取数据
数据从2004年1月到2019年9月
import json
from lxml import etree
import requests
import time
# 由于之前将网页上需要的连接都爬取保存了,这里就直接读取
with open('test.txt','r') as f:
url_set=f.read()
# 数据分割
list_url = list(url_set.split('\n'))
# 倒序(之前爬取是从新到旧)
url_list=list_url[::-1]
# 请求头
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'}
# 计数用
bb=0
# 函数爬取单页
def get_url(url_,headers):
response = requests.get(url=url_,h