Issue
I am trying to get an attribute of an element but I got None for that element Here's my code
import requests
from bs4 import BeautifulSoup as bs
res = requests.get('https://services.paci.gov.kw/card/inquiry?lang=ar&serviceType=2')
#print(res.text)
with open('Output.txt', 'w') as f:
f.write(str(res.text))
soup = bs(res.text, 'html.parser')
vToken = soup.find('input', attrs={'name': '__RequestVerificationToken'}, first=True)
print(vToken)
print(vToken['value'])
I checked the Output.txt file and I found that attribute implemented but couldn't get its attribute
Solution
Skip the first=True
argument from your find()
, it will throw:
TypeError: 'NoneType' object is not subscriptable
Example:
import requests
from bs4 import BeautifulSoup as bs
res = requests.get('https://services.paci.gov.kw/card/inquiry?lang=ar&serviceType=2')
soup = bs(res.text, 'html.parser')
vToken = soup.find('input', attrs={'name': '__RequestVerificationToken'})
print(vToken['value'])
Output:
CfDJ8Jg8_Y_lKLtGsMsCG9ry3AgPF3n0c5Zc7jzzJ0hYmIv2my6IqtFlABkZLpwb3f9JfCP3-Yhr_P4bvwp_jyw47G6MTcAAUx9ZBE82oSQ4tpSrJxS4vxtJj6LPZ2vaLwGDgiYitq3qYiJmNZvsg_FHOj0
Answered By - HedgeHog
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.