gpt4 book ai didi

Python beautifulsoup - 获取输入值/TypeError : 'NoneType' object is not subscriptable

转载 作者:太空宇宙 更新时间:2023-11-03 20:51:26 25 4
gpt4 key购买 nike

尝试查找 formkey 但出现错误:

TypeError: 'NoneType' object is not subscriptable

关于this webpage .

需要找到该值。我正在寻找的东西可以找到查看源代码:https://wellgosh.com/customer/account/create/和 control+f name="form_key"value=

formkey_acc = soup.find('input', {'name': 'form_key'})['value']
s = requests.session()

def c_acc():
acc = s.get('https://wellgosh.com/customer/account/create/')
soup = bs(acc.text, 'html.parser')
formkey_acc = soup.find('input', {'name': 'form_key'})['value']
print(formkey_acc)
formkey_acc = soup.find('input', {'name': 'form_key'})['value']

类型错误:“NoneType”对象不可订阅

最佳答案

他们对请求的默认用户代理进行 403 处理...

import requests
from bs4 import BeautifulSoup as bs

def c_acc(s):
acc = s.get(
'https://wellgosh.com/customer/account/create/',
headers={'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36"}
)
soup = bs(acc.text, 'html.parser')
formkey_acc = soup.find('input', {'name': 'form_key'}).get('value')
print(formkey_acc)

s = requests.session()
c_acc(s)

关于Python beautifulsoup - 获取输入值/TypeError : 'NoneType' object is not subscriptable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56287301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com