你好,我想从一个网站https://www.nsekra.com/上搜集信息。我们需要从下拉列表中选择Non-Individual
,然后输入PAN作为AAAHA0064Q
,以及captcha number
,它在每次访问或打开网站时生成一个随机数。之后,我们需要按Search
按钮,以便获取所需的信息。你知道吗
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)
输出
print('Fetched Catpcha No. -> ',s);
Fetched Catpcha No. -> 757205
print(soup2.prettify());
print('KRA Name : '+name)
KRA Name :  
预期产量
KRA Name : CVL KRA
正如你所见,我可以得到验证码号码,但当我试图把它传递给网站,它重新生成新的号码,每当网站被访问。因此,基本上,上面的代码会获取验证码号码,但在访问网站时,会生成新号码,而不是新号码,传递旧号码或以前的号码,而不是访问网站时的当前号码。如何获取并利用动态生成的数字来获取我感兴趣的结果?我喜欢坚持使用requests
库来完成它。
目前没有回答
相关问题 更多 >
编程相关推荐