2017-09-11 6 views
0

저는 최근에 파이썬으로 모험을 해왔으며, 제가 찾은 코드를 혼합하여 약간의 것을 배우려고 시도했습니다. 미래에 사용할 수있는 무언가로. 내가 링크를 인쇄 할 때, 그것이 내가 선호 할 것 같은 무언가가되는Python 프로젝트 작은 문제 뭔가를 인쇄 해낼 수없는 것 같습니다.

https://v3rmillion.net/showthread.php

대신 말한다 있지만 나는 거의 완전히 프로젝트를했습니다 존재 :

https://v3rmillion.net/showthread.php?tid=393794

import requests,os,urllib,sys, webbrowser, bs4 

from bs4 import BeautifulSoup 

def startup(): 
    os.system('cls') 
    print('Discord To Profile') 
    user = raw_input('Discord Tag: ') 
    r = requests.get('https://www.google.ca/search?source=hp&q=' + user + ' site:v3rmillion.net') 
    soup = BeautifulSoup(r.text, "html.parser") 
    print soup.find('div',{'id':'resultStats'}).text 

    #This part below is where I'm having the issue. 
    content=r.content.decode('UTF-8','replace') 
    links=[] 
    while '<h3 class="r">' in content: 
     content=content.split('<h3 class="r">', 1)[1] 
     split_content=content.split('</h3>', 1) 
     link='http'+split_content[1].split(':http',1)[1].split('%',1)[0] 
     links.append(link) 
     #content=split_content[1] 
    for link in links[:5]: 
     print(link) 

startup() 
+1

당신의 _question_은 무엇입니까? 자신이 원하는 질문을 질문 자체에 표시하려면 게시물을 편집하십시오. 사람들이 당신이 묻는 것을 알아 내기 위해 임의의 사이트에서 자바 스크립트를 기꺼이 사용할 수 있다고하더라도 (나는 아닙니다), 결과 Q & A는 링크가 썩어 버린 후에 오는 사람에게는 아무런 가치가 없습니다. –

+0

그것은 https://v3rmillion.net/showthread.php를 보여줍니다 단순히 표시해야 할 때 https://v3rmillion.net/showthread.php?tid=393794 – Biologic

+0

외부 링크가 잘못되었습니다, mkay – JacobIRR

답변

0

귀하의 코드에서 되돌아 오는 결과를 살펴 보았습니다. <cite> 태그를 찾아 코드를 상당히 줄일 수 있다고 생각합니다 :

def startup(): 
    os.system('cls') 
    print('Discord To Profile') 
    user = raw_input('Discord Tag: ') 
    r = requests.get('https://www.google.ca/search?source=hp&q=' + user + ' site:v3rmillion.net') 
    soup = BeautifulSoup(r.text, "html.parser") 
    links=[] 
    for link in soup.find_all('cite'): 
     links.append(link.string) 
    for link in links[:5]: 
     print(link)