mardi 24 mars 2015

(Web Scraping) TypeError: unsupported operand type(s) for -: 'str' and 'int'

I'm trying to web scrape some data, at first I got an encoding error but now I am getting the type error listed above. I double checked my "-" and they have been done correctly. Here is a portion of my code:



# attempt to scrape messages off CC links
allPosts = []
## testing for just one data point (essayData[10])
for row in essayData[10]:
r = requests.get(row)
soup = BeautifulSoup(r.content)
## takes all divs with class Message, adds it to allPosts
for item in soup.find_all('div', class_="Message"):
item.decode("utf-8")
allPosts.append(item.text)
## creates separate files for each user post
for i in range(1, len(essayData) + 1):
with open("post_" + str(i) + ".csv", "wb") as csvFile:
f = csv.writer(csvFile, delimiter = ",")
for row in allPosts:
row.encode("ascii", "ignore")
f.writerow([row])




Aucun commentaire:

Enregistrer un commentaire