2017-09-11 4 views
0

最近、私は最近Pythonで冒険してきました。私は見つけたコードを混ぜ合わせることで少しのことを学んできましたそれは私が将来使用することになるかもしれないものに変換します。私はリンクをプリントアウトするとき、それは私が好むようなものであることの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_は何ですか?投稿を編集して質問自体に何を表示してください。あなたが何を求めているのか分かり易くするためにJavaScriptをいくつかのランダムなサイトから利用しても、リンクが崩れた後に来る人には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) 
関連する問題