Python 完整URL不是';无法正确解析到电报机器人
我编写了以下内容,以自动解析从不断更新的.txt文件到电报机器人的文本Python 完整URL不是';无法正确解析到电报机器人,python,api,telegram,Python,Api,Telegram,我编写了以下内容,以自动解析从不断更新的.txt文件到电报机器人的文本 import urllib.parse import time import requests def post_to_telegram(msg): print(msg) base_url = 'https://api.telegram.org/bot&text="{}"'.format(msg) requests.get(base_url) urr = "
import urllib.parse
import time
import requests
def post_to_telegram(msg):
print(msg)
base_url = 'https://api.telegram.org/bot&text="{}"'.format(msg)
requests.get(base_url)
urr = ""
name = ""
price = ""
ourLines=0
while(True):
file1 = open('example.txt', 'r')
Lines = file1.readlines()
time.sleep(1)
while(True):
if(ourLines==len(Lines)):
break
else:
txt = Lines[ourLines].strip()
tlist = txt.split("&")
ourLines=ourLines+1
for subtxt in tlist:
if "eventurl=" in subtxt:
a = subtxt[9:len(subtxt) - 3]
url = 'www.bbey43.com/#'+a.replace("%23", "/")
#print(url)
urr = url
elif "bet=" in subtxt:
name = urllib.parse.unquote(subtxt[4:len(subtxt)])
#print(name)
elif "price\":" in subtxt:
a = subtxt.split("price")[1]
price = a.split("\"")[2]
#print(price)
post_to_telegram(urr + " "+ name + " " + price)
“name”和“price”已成功发布到bot,但“url”未正确发布。唯一能通过的是“bbey43.com/#/”,最终解决方案相当简单。由于“#”是URL的一部分,因此在解析时需要特殊格式 简单地添加%23而不是#解决了它