似乎Python项目有点问题,我无法弄清楚打印的东西(Python project little i

2019-10-30 08:33发布

所以,我最近一直在四处冒险使用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()

Answer 1:

我看着从您的代码回来的结果,我认为,你可以显通过寻找降低你的代码<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)


文章来源: Python project little issue I can't seem to figure out to print something