|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import requests
- import bs4
- import pypinyin
- def find_data(res):
- soup = bs4.BeautifulSoup(res.text, "html.parser")
- content = soup.find_all("td")
- if content:
- content.pop(0)
- return content
- def main(idiom):
- url = "".join(pypinyin.lazy_pinyin(idiom))
- url = f"https://chengyu.51240.com/{url}__chengyuchaxun/"
- res = requests.get(url)
- content = find_data(res)
- return content
- if __name__ == "__main__":
- while True:
- idiom = input("请输入要查找的成语:")
-
- content = main(idiom)
- print()
- if not content:
- print("抱歉,没有找到该成语\n")
- continue
- for each in content:
- print(each.text.replace(" 更多:https://www.51240.com/ ", ""), end="\n\n")
- print("=====================================================================\n")
复制代码 |
|