[SOLVED] ‘NoneType’ object is not iterable in scrapper


This Content is from Stack Overflow. Question asked by Kouros

I am trying to write scrapper for “free-proxy.cz” website, however, I am facing a problem

I know my “port” section is wrong, but I don’t know the problem and how to fix it.

here is the code:

import requests
from bs4 import BeautifulSoup
import base64

urls = ['http://free-proxy.cz/en/proxylist/country/all/socks5/date/all',

for url in urls:
    r = requests.get(url)
    soup = BeautifulSoup(r.text, 'html.parser')
    table = soup.find('table', {'id': 'proxy_list'})
    for row in table.find('tbody').find_all('tr'):
        for ip in row.find('script'):
        for port in row.find('span', attrs='fport'):

** I commented the last line because the port grabber is not working correct.

the result of running the above code is :

Traceback (most recent call last):
  File "LOCATIONmain.py", line 22, in <module>
    for port in row.find('span', attrs='fport'):
TypeError: 'NoneType' object is not iterable

what is the issue here ?


    span_rows = row.find('span', attrs='fport')
    if span_rows is not None:
        for port in span_rows:

This Question was asked in StackOverflow by Kouros and Answered by mikelus It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?