赞
踩
import re
import requests
from requests import RequestException
import time
import random
def get_page(url):
try:
headers = {
'Referer': 'https://blog.csdn.net', # 伪装成从CSDN博客搜索到的文章
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.75 Safari/537.36'
# 伪装成浏览器
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.text
return None
except RequestException:
print('请求出错')
return None
def parse_page(html):
try:
read_num = int(re.compile('').search(html).group(1))
return read_num
except Exception:
print('解析出错')
return None
def main():
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。