2016-10-24 4 views
0

트위터를 구문 분석하려고하는데 원하는 출력은 짹짹의 URL, 짹짹 날짜, 보낸 사람 및 트위터 자체입니다. 오류는 없지만 결과는 비어 있습니다. 내가 코드가 본 계약 인 문제를 찾을 수 없습니다 : 당신이 나를 도울 수 있다면 그래서 내가 내 논문에BeautifulSoup 결과가 비어 있습니다.

from bs4 import BeautifulSoup 
import urllib.request 
import openpyxl 
wb= openpyxl.load_workbook('dene1.xlsx') 
sheet=wb.get_sheet_by_name('Sayfa1') 
headers = {} 
headers['User-Agent'] = "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.27 Safari/537.17" 
url = 'https://twitter.com/search?q=TURKCELL%20lang%3Atr%20since%3A2012-01-01%20until%3A2012-01-09&src=typd&lang=tr' 
req = urllib.request.Request(url, headers = headers) 
resp = urllib.request.urlopen(req) 
respData = resp.read() 
soup = BeautifulSoup(respData , 'html.parser') 
gdata = soup.find_all("div", {"class": "content"}) 
for item in gdata: 
    try: 
     items2 = item.find('a', {'class': 'tweet-timestamp js-permalink js-nav js-tooltip'}) 
     items21=items2.get('href') 
     items22=items2.get('title') 
    except: 
     pass 
    try: 
     items1 = item.find('span', {'class': 'username js-action-profile-name'}).text 
    except: 
     pass 
    try: 
     items3 = item.find('p', {'class': 'TweetTextSize js-tweet-text tweet-text'}).text 
     sheet1=sheet.append([items21, items22,items1,items3]) 
    except: 
     pass 
wb.save('dene1.xlsx') 

관련

의 데이터를 사용하는 것 좋은 것 당신의 excepts에

답변

0

Eevery 라인은 원인

import urllib.request 
from bs4 import BeautifulSoup 


headers = { 
    'User-Agent': "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.27 Safari/537.17"} 

url = 'https://twitter.com/search?q=TURKCELL%20lang%3Atr%20since%3A2012-01-01%20until%3A2012-01-09&src=typd&lang=tr' 
req = urllib.request.Request(url, headers = headers) 
resp = urllib.request.urlopen(req) 
respData = resp.read() 

soup = BeautifulSoup(respData, 'html.parser') 
gdata = soup.find_all("div", {"class": "content"}) 
for item in gdata: 
    items2 = item.find('a', {'class': 'tweet-timestamp js-permalink js-nav js-tooltip'}, href=True) 
    if items2: 
     items21 = items2.get('href') 
     items22 = items2.get('title') 
     print(items21) 
     print(items22) 
    items1 = item.find('span', {'class': 'username js-action-profile-name'}) 
    if items1: 
     print(items1.text) 
    items3 = item.find('p', {'class': 'TweetTextSize js-tweet-text tweet-text'}) 
    if items3: 
     print(items3.text) 

은 이제 출력을 많이 볼 수 있습니다 당신은 말 그대로 모든 예외를 잡기 위해 빈 excepts를 사용할 때 오류가 적어도 한 번, 당신이 그들을 볼 수 없습니다.

관련 문제