【发布时间】:2017-09-11 19:06:32
【问题描述】:
所以,我最近一直在使用 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()
【问题讨论】:
-
那么您的问题是什么?请edit您的帖子在问题本身中显示您想要的内容。即使人们愿意从某个随机站点启用 JavaScript 只是为了弄清楚您在问什么(我不是),但由此产生的问答对于在链接失效后出现的任何人来说都是毫无价值的。
-
外部链接不好,mkay
标签: python html beautifulsoup urllib