Question

 import urllib, urllib2
 from bs4 import BeautifulSoup, Comment
 url='http://www.amazon.in/product-reviews/B00EJBA7HC/ref=cm_cr_pr_top_link_1?ie=UTF8&pageNumber=1&showViewpoints=0&sortBy=bySubmissionDateDescending'
 content = urllib2.urlopen(url).read()
 soup = BeautifulSoup(content, "html.parser")
 fooId = soup.find('input',name='ASIN',type='hidden') #Find the proper tag
 value = fooId['value']
 print value

I need this code to print the ASIN ID for the product from the URL given.

Instead, I get the following error:

TypeError: find() got multiple values for keyword argument 'name'

Please help.

Was it helpful?

Solution

The reason why this is breaking is because you have the soup.find function signature wrong. There is no first positional argument. The function signature looks like this:

def find(self, name=None, attrs={}, recursive=True, text=None, **kwargs)

So 'input' is assigned to the first keyword argument(in this case, name). So now you have 2 values assigned to keyword argument 'name'.

The correct syntax for what you are trying to do is likely this:

fooId = soup.find(name='input', attrs={'name': 'ASIN', 'type': 'hidden'})

This says, find all <input>'s in the HTML you are parsing with the attributes listed described in attrs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top