0
url = "https://technet.microsoft.com/en-us/library/hh135098(v=exchg.150).aspx"
r = requests.get(url)
soup = BeautifulSoup(r.content, 'lxml')
table = soup.find_all('table', attrs={"responsive": "true"})[0]
for rows in table.find_all('tr')[1]:
    item = []
    for val in rows.find('td'):
        item.append(val.text.strip())
        print (item)

Traceback (most recent call last):
    File "<stdin>", line 3, in <module>
TypeError: 'int' object is not interable

Line 4 refers to for val in rows.find('td'):

2
  • 1
    what does rows.find('td') returns ? Commented May 8, 2017 at 15:06
  • 1
    Line 4 or line 3? for val in rows.find('td'): is line 7 in the above code. If you include the full traceback, it actually shows you the offending line. Commented May 8, 2017 at 15:10

1 Answer 1

1

In for val in rows.find('td'): when there's no td found in the rows, it returns -1 an int object which you are trying to loop, hence the error.

The correct approach:

>>> for rows in table.find_all('tr'):
...   item = []
...   for val in rows.find_all('td'):
...     item.append(val.text.strip())
...   print(item)
... 
[]
['Exchange Server 2016 CU5', 'March 21, 2017', '15.01.0845.034']
['Exchange Server 2016 CU4', 'December 13, 2016', '15.01.0669.032']
['Exchange Server 2016 CU3', 'September 20, 2016', '15.01.0544.027']
['Exchange Server 2016 CU2', 'June 21, 2016', '15.01.0466.034']
['Exchange Server 2016CU1', 'March 15, 2016', '15.01.0396.030']
['Exchange Server 2016 RTM', 'October 1, 2015', '15.01.0225.042']
['Exchange Server 2016 Preview', 'July 22, 2015', '15.01.0225.016']
Sign up to request clarification or add additional context in comments.

1 Comment

I can be a bonehead sometimes. Thanks sir!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.