Last active
November 14, 2021 02:24
-
-
Save RRRoger/e487f687e3d0feb671434962769774c7 to your computer and use it in GitHub Desktop.
成语接龙
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
python CNlink.py 正 | |
output: | |
正直无私 | |
正始之音 | |
正大光明 | |
正己守道 | |
正理平治 | |
正心诚意 | |
正身率下 | |
正本清源 | |
正经八百 | |
正正之旗 | |
""" | |
import requests | |
import sys | |
reload(sys) | |
import re | |
def get_words(): | |
return sys.argv[1:] | |
sys.setdefaultencoding('utf-8') | |
char0 = "寇" | |
words = get_words() | |
char = words[0] if words else char0 | |
char = char.decode('utf8') | |
res = requests.get("https://hanyu.baidu.com/s?wd=%s开头成语&from=poem" % char) | |
regex = r"(%s[^\x00-\xff]{3})&ptype=zici" | |
x = re.findall(regex % char, res.text) | |
x = list(set(x)) | |
for i in x[:10]: | |
print i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment