A story when you want to specify the name attribute when getting the html element with BeautifulSoup.
#Acquisition example
source = soup.find('div', class_='hogehoge')
Basically, get by specifying soup.find ('tag name', attribute name ='value') in this way. However, if you write this in the name attribute, an error will occur.
#Acquisition example
source = soup.find('input', name='hogehoge', type='hidden')
Execution result
TypeError: find() got multiple values for keyword argument 'name'
This seems to be an error because the argument name is already defined in the find method of BeautifulSoup.
source = soup.find('input', attrs={'name': 'hogehoge', 'type': 'hidden'})
It seems that you can specify the name attribute by passing a dictionary type value to the argument attrs, so specify it with this.
source = soup.find('input', {'name': 'hogehoge', 'type': 'hidden'})
You can get the same result even if you omit the argument, so choose the one you like.
Parameters for find function [Python: BeautifulSoup-Get attribute values based on name attributes](https://www.it-swarm.dev/ja/python/python%EF%BC%9Abeautifulsoup%E5%90%8D%E5% 89% 8D% E5% B1% 9E% E6% 80% A7% E3% 81% AB% E5% 9F% BA% E3% 81% A5% E3% 81% 84% E3% 81% A6% E5% B1% 9E% E6% 80% A7% E5% 80% A4% E3% 82% 92% E5% 8F% 96% E5% BE% 97% E3% 81% 97% E3% 81% BE% E3% 81% 99 / 1068412706 /)
Recommended Posts