【发布时间】:2016-02-24 01:08:16
【问题描述】:
这是我现在的代码:
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?®ionid=" + 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))
但是,我不断收到错误消息:
for reg in Region:
TypeError: 'int' object is not iterable
当我尝试运行它时。
我做错了什么?
谁能帮我解决这个问题?感谢您提供任何反馈。
【问题讨论】:
-
你已经定义了
Region = 7236,这是一个int,所以,就像错误所说的,你不能迭代它。 -
你想做什么?你应该用
7236这个号码做什么? -
7236 只是一个地区的数字,例如罗马
-
好的,那么如果您知道
7236是Region的值,那么您希望用for reg in 7236做什么? -
不知道数字是不可迭代的。
标签: python loops web-crawler iterable