Quando pesquisamos, por exemplo, tweets com uma determinada hashtag até o dia 24 de abril de 2014, ele nos retorna resultados até do dia 23 de abril de 2014 até 17:00.
Como resolver isso? Se buscarmos um dia a frente pode ser que fique muito pesado para carregar toda a url
quinta-feira, 30 de abril de 2015
quarta-feira, 29 de abril de 2015
andamento..
Melhoria do código urgente.
prox passos: metodo getPreviousDay, ciclo por dia até a data limite, gerar url modificada c data anterior
*mudar dia str -> int
método replace http://wiki.python.org.br/ManipulandoStringsComPython
prox passos: metodo getPreviousDay, ciclo por dia até a data limite, gerar url modificada c data anterior
*mudar dia str -> int
método replace http://wiki.python.org.br/ManipulandoStringsComPython
quarta-feira, 25 de março de 2015
inversão data e hora
Estava com um problema, só conseguia pegar a data e hora juntas através do crawler e essa vinha no formara "hora - data" o que dificultava colocar em uma ordem cronológica de tweets;
Consertado -> "data - hora" permitindo através de um group by exibir pelo dia que queremos. Podemos até separar data e hora em duas colunas distintas, caso a gente queira definir um limite de dias
Consertado -> "data - hora" permitindo através de um group by exibir pelo dia que queremos. Podemos até separar data e hora em duas colunas distintas, caso a gente queira definir um limite de dias
quarta-feira, 11 de março de 2015
terça-feira, 3 de março de 2015
Selenium web driver for python <<<<-
a função scroll down está funcionando no programa teste, agora é preciso adaptá-lo e implementar no programa crawler do twitter.
quarta-feira, 25 de fevereiro de 2015
username ok
pegando o nome já;
agora falta data
#author: Maria Beatriz Vaz
import urlparse
import urllib
import codecs
from bs4 import BeautifulSoup
import psycopg2
import sys
try:
conn = psycopg2.connect("dbname='tweet_ic' user='postgres' host='localhost' port='5432' password='8001007'")
print "Connected to database"
except:
print "I am unable to connect to the database"
cur=conn.cursor()
urls = ["https://twitter.com/search?q=%23marcocivil%20since%3A2014-02-03%20until%3A2014-05-23&src=typd"]
visited = [urls[0]]
while len(urls) > 0:
try:
htmltext = urllib.urlopen(urls[0]).read()
except:
print urls[0]
soup = BeautifulSoup(htmltext)
#print soup.get_text().encode("utf-8")
visited.append(urls[0])
tweets = []
names = []
i = 0
for tag in soup.findAll('div', { "class" : "content" }) :
for tweet in tag.findAll('p', {"class" : "js-tweet-text tweet-text"}):
tweet_text = tweet.get_text().encode("utf-8")
tweets.insert(0,tweet_text)
for name in tag.findAll ('strong', {"class" : "fullname js-action-profile-name show-popup-with-id"}):
name_text = name.get_text().encode("utf-8")
names.insert(0,name_text)
i=i+1
print 'chegou'
while i>=0:
try:
print 'name: ' + names[i-1] + ' - tweet: ' + tweets[i-1]
cur.execute(""" INSERT INTO teste_old (name , tweet) VALUES ( %(name)s, %(tweet)s )""", ({ "name" : names[i-1] , "tweet" : tweets[i-1]}))
conn.commit()
except Exception as inst:
conn.rollback()
print 'Igual'
i=i-1
print ">>>visitou: " + urls[0]
urls.pop(0)
if conn:
conn.close()
agora falta data
#author: Maria Beatriz Vaz
import urlparse
import urllib
import codecs
from bs4 import BeautifulSoup
import psycopg2
import sys
try:
conn = psycopg2.connect("dbname='tweet_ic' user='postgres' host='localhost' port='5432' password='8001007'")
print "Connected to database"
except:
print "I am unable to connect to the database"
cur=conn.cursor()
urls = ["https://twitter.com/search?q=%23marcocivil%20since%3A2014-02-03%20until%3A2014-05-23&src=typd"]
visited = [urls[0]]
while len(urls) > 0:
try:
htmltext = urllib.urlopen(urls[0]).read()
except:
print urls[0]
soup = BeautifulSoup(htmltext)
#print soup.get_text().encode("utf-8")
visited.append(urls[0])
tweets = []
names = []
i = 0
for tag in soup.findAll('div', { "class" : "content" }) :
for tweet in tag.findAll('p', {"class" : "js-tweet-text tweet-text"}):
tweet_text = tweet.get_text().encode("utf-8")
tweets.insert(0,tweet_text)
for name in tag.findAll ('strong', {"class" : "fullname js-action-profile-name show-popup-with-id"}):
name_text = name.get_text().encode("utf-8")
names.insert(0,name_text)
i=i+1
print 'chegou'
while i>=0:
try:
print 'name: ' + names[i-1] + ' - tweet: ' + tweets[i-1]
cur.execute(""" INSERT INTO teste_old (name , tweet) VALUES ( %(name)s, %(tweet)s )""", ({ "name" : names[i-1] , "tweet" : tweets[i-1]}))
conn.commit()
except Exception as inst:
conn.rollback()
print 'Igual'
i=i-1
print ">>>visitou: " + urls[0]
urls.pop(0)
if conn:
conn.close()
crawler (python)
#author: Maria Beatriz Vaz
import urlparse
import urllib
import codecs
from bs4 import BeautifulSoup
import psycopg2
import sys
try:
conn = psycopg2.connect("dbname='tweet_ic' user='postgres' host='localhost' port='5432' password='8001007'")
print "Connected to database"
except:
print "I am unable to connect to the database"
cur=conn.cursor()
urls = ["https://twitter.com/search?q=%23marcocivil%20since%3A2014-02-03%20until%3A2014-05-23&src=typd"]
visited = [urls[0]]
while len(urls) > 0:
try:
htmltext = urllib.urlopen(urls[0]).read()
except:
print urls[0]
soup = BeautifulSoup(htmltext)
print soup.get_text().encode("utf-8")
visited.append(urls[0])
for tag in soup.findAll('div', { "class" : "content" }) :
for tweet in tag.findAll('p', {"class" : "js-tweet-text tweet-text"}):
print ">>>>nova tag"
tweet_text = tweet.get_text().encode("utf-8")
print tweet_text
cur.execute(""" INSERT INTO teste_old (tweets) VALUES (%(tweets)s)""", ({"tweets" : tweet.get_text().encode("utf-8")}))
conn.commit()
print ">>>visitou: " + urls[0]
urls.pop(0)
if conn:
conn.close()
Já consigo pegar o texto de tweets de uma determinada página. Agora preciso pegar, pelo menos, o usuário e a data daquele tweet.
Preciso saber também como faz para o programa descer a página.
Com o site de pesquisa https://twitter.com/search?q=%23marcocivil%20since%3A2014-02-03%20until%3A2014-05-23&src=typd
só capturei 19 tweets, ´pois é o que aparece até abaixarmos mais a tela.
import urlparse
import urllib
import codecs
from bs4 import BeautifulSoup
import psycopg2
import sys
try:
conn = psycopg2.connect("dbname='tweet_ic' user='postgres' host='localhost' port='5432' password='8001007'")
print "Connected to database"
except:
print "I am unable to connect to the database"
cur=conn.cursor()
urls = ["https://twitter.com/search?q=%23marcocivil%20since%3A2014-02-03%20until%3A2014-05-23&src=typd"]
visited = [urls[0]]
while len(urls) > 0:
try:
htmltext = urllib.urlopen(urls[0]).read()
except:
print urls[0]
soup = BeautifulSoup(htmltext)
print soup.get_text().encode("utf-8")
visited.append(urls[0])
for tag in soup.findAll('div', { "class" : "content" }) :
for tweet in tag.findAll('p', {"class" : "js-tweet-text tweet-text"}):
print ">>>>nova tag"
tweet_text = tweet.get_text().encode("utf-8")
print tweet_text
cur.execute(""" INSERT INTO teste_old (tweets) VALUES (%(tweets)s)""", ({"tweets" : tweet.get_text().encode("utf-8")}))
conn.commit()
print ">>>visitou: " + urls[0]
urls.pop(0)
if conn:
conn.close()
Já consigo pegar o texto de tweets de uma determinada página. Agora preciso pegar, pelo menos, o usuário e a data daquele tweet.
Preciso saber também como faz para o programa descer a página.
Com o site de pesquisa https://twitter.com/search?q=%23marcocivil%20since%3A2014-02-03%20until%3A2014-05-23&src=typd
só capturei 19 tweets, ´pois é o que aparece até abaixarmos mais a tela.
Assinar:
Postagens (Atom)