Hello I am trying to scrape information from a website https://www.nsekra.com/. We need to select Non-Individual
from dropdown then enter the PAN as AAAHA0064Q
, and the captcha number
which generates a random number every time the website is visited or opened. After that we need to press Search
button so that the required information can be fetched.
import requests
from bs4 import BeautifulSoup
resp = requests.get('https://www.nsekra.com/')
soup = BeautifulSoup(resp.text,'lxml')
dictinfo = {i['name']:i.get('value','') for i in soup.select('input[name]')}
# trying to enter PAN as 'AAAHA0064Q'
dictinfo['txtPan']='AAAHA0064Q'
# trying to get captcha number & passing to textbox
captcha_number = soup.select_one("#lblDynamicCode").text
print('Fetched Catpcha No. -> ',captcha_number);
dictinfo['txtImageBox'] = captcha_number
# passsing pan no. & captcha number to the request method
resp2 = requests.post('https://www.nsekra.com/',data=dictinfo)
soup2 = BeautifulSoup(resp2.text,'lxml')
name = soup2.select_one('#lblKra_name').text
print('KRA Name : '+name)
OUTPUT
print('Fetched Catpcha No. -> ',s);
Fetched Catpcha No. -> 757205
print(soup2.prettify());
print('KRA Name : '+name)
KRA Name :  
Expected Output
KRA Name : CVL KRA
As you can see I able to get the captcha number, but when I'm trying to passed it to the website, it regenerating new number everytime when the website is visited. So basically, the above code does fetch the captcha number but while visting to the website, new number is generated & instead of new number, the old or previous number is passed, & not the current one at when the website is visited. How can I grab and make use of that dynamically generated number in order to fetch the results I'm interested in?I like to stick to the requests
library to get it done.
from Unable to catch and input some dynamically generated number in an inputbox to populate some result
No comments:
Post a Comment