I am writing a parser bot that checks a site for a domain name through the whois service. In the terminal the parsing goes fine and the information is displayed, but when need to send this text in the chat, an error is generated (send_message() missing 1 required positional argument: 'text')
this is just a link check:
@bot.message_handler(commands=['getpng'])
def get_screenshot(message):
@bot.message_handler(commands=['getpng'])
def get_screenshot(message):
uid = message.chat.id
url = ""
try:
url = message.text.split(' ')[1]
except IndexError:
bot.send_message(uid, 'You have not entered URL!')
return
if not validators.url(url):
bot.send_message(uid, 'URL is invalid!')
else:
**this is the problematic part of the code:**
browser = webdriver.Chrome()
browser.get('https://www.nic.ru/whois/')
input1 = browser.find_element_by_xpath('//*[@id="rc-web-client"]/div/div/div[1]/main/div[1]/div[1]/div/div/div/input')
input1.send_keys(url)
time.sleep(2)
button = browser.find_element_by_xpath('//*[@id="rc-web-client"]/div/div/div[1]/main/div[1]/div[1]/div/button/span[1]')
button.click()
time.sleep(5)
infa = browser.find_element_by_xpath('//*[@id="rc-web-client"]/div/div/div[1]/main/div[1]/div[4]/div/div[2]/a[1]')
infa1 = infa.text
#print(infa1)
bot.send_message(infa1)
I get that error when I run the code.
why is the text in the infa1 not visible? how can i solve this?
UPD:
Возникло исключение: TypeError (note: full exception trace is shown but execution is paused at: get_screenshot)
send_message() missing 1 required positional argument: 'text'
File "C:\Users\Petyal\Desktop\something.py", line 41, in get_screenshot (Current frame)
bot.send_message(infa1)
File "C:\Users\Petyal\Desktop\something.py", line 56, in <module>
bot.infinity_polling()
CodePudding user response:
I suppose you missed the chat_id parameter in the send_message function
Try adding a parameter:
bot.send_message(chat_id, text)