接口没了, 脚本失效
前两天博主网络通识课要期末考试啦, 不想百度谷歌, 于是找了一波接口, 还真被我发现有大佬已经写好接口了, 不说话, 上py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2019-05-13 14:55:01
# @Link : https://www.fengwenhua.top
import requests
from urllib.parse import urlencode
from random import choice
from requests.exceptions import ConnectionError, ReadTimeout
def get_answer(question):
User_Agents_List = [
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50',
'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50',
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1',
'Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11',
'Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36',
]
headers = {
'User-Agent': choice(User_Agents_List),
'Accept-Encoding': 'gzip, deflate, sdch',
'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7'
}
params = {
'w': question,
}
url = "http://api.fm210.cn/wangke/cx.php?" + urlencode(params)
try:
r = requests.get(url, headers=headers, timeout=5)
if r.status_code == 200:
return r.text
except ConnectionError:
print('访问失败', url)
except ReadTimeout:
print('访问超时', url)
if __name__ == '__main__':
# 将问题粘贴到这里, 然后直接运行即可
question = "3200K—5500K范围的色温,都适用于灯光彩色胶片的拍摄。"
print(get_answer(question))
由于本人用st3运行, 没有装可以输入的插件, 因此只能粘贴一下运行一下喽
~
最后, 靠着这个代码, 本人在智慧树中那门摄影基础期末考了100分!!!