-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.py
More file actions
22 lines (22 loc) · 745 Bytes
/
test.py
File metadata and controls
22 lines (22 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import urllib.request
uri_base = "https://api.ltp-cloud.com/analysis/?"
api_key = "F1a5e3k9w7UPcXnfjcETgQFTwWZVoCvKwIwEEtmQ"
text = "我爱北京天安门"
# Note that if your text contain special characters such as linefeed or '&',
# you need to use urlencode to encode your data
format = 'plain'
pattern = "all"
text = urllib.request.quote(text)
url = (uri_base
+ "api_key=" + api_key + "&"
+ "text=" + text + "&"
+ "format=" + format + "&"
+ "pattern=" + 'pos')
print(url)
response = urllib.request.urlopen(url)
content = response.read().strip().decode('utf8')
print (content)
ans = content.split()
for a in ans:
if a[-3:] == "_ns":
print(a.replace('_ns',''))