0

Here is my code right now:

front_deeplink = ("http://www.jsox.de")
Spider = 20
Region = 7236


def trade_spider(max_pages):
for reg in Region:
    page = 0
    while page <= max_pages:
        page += 1
        r = requests.get("http://www.jsox.de/affiliatesearch.aspx?&regionid=" + str(reg) + "&pid=" + str(page))
        soup = BeautifulSoup(r.content)

        g_data = soup.find_all("div", {"class": "gridHeadOuter productInfoOuter"})

        for item in g_data:
            Header = item.find_all("div", {"class": "offerInto"})
            Header_final = (Header[0].contents[0].text.strip())
            price = item.find_all("strong", {"class": "priceBig priceBlock"})
            Price_final = (price[0].text.strip())
            Deeplink = item.find_all("a")
            for t in set(t.get("href") for t in Deeplink):        
                Deeplink_final = (str(front_deeplink) + t)

            print("Header: " + Header_final + " | " + "Price: " + Price_final[:-1] + " | " + "Deeplink: " + Deeplink_final)

trade_spider(int(Spider))

However, I keep getting the error message:

for reg in Region:
TypeError: 'int' object is not iterable

when I try and run this.

What am I doing wrong?

Can anyone help me with that? Any feedback is appreciated.

8
  • You have defined Region = 7236, which is an int, so, like the error says, you cannot iterate over it. Commented Nov 21, 2015 at 16:00
  • What are you trying to do? what are you supposed to do with the number 7236? Commented Nov 21, 2015 at 16:27
  • 7236 is simpy a number for a region, e.g Rome Commented Nov 21, 2015 at 16:33
  • OK, then what were you expecting to do with for reg in 7236 if you know that 7236 is the value of Region? Commented Nov 21, 2015 at 17:00
  • Had no clue that numbers are not iterable. Commented Nov 21, 2015 at 17:08

2 Answers 2

3

In your code you have this declaration:

Region = 7236

Then, you try to do this:

for reg in Region:

Clearly, a Region is just a number, you can't iterate over it as you would, say, iterate over a list. Use for to traverse lists, or other iterable objects - numbers are simply not iterable.

Sign up to request clarification or add additional context in comments.

Comments

1

Use range() or xrange(), which receive an int and produce an iterable.

Comments

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.