我是python的新手。尝试做一些网络抓取(获取一个URL,非常简单),我的函数起作用了。但是,当我尝试将函数与discord.py一起使用时,它将在URL末尾返回“ 27%”。
URL为“'https://readms.net'”
import requests
from bs4 import BeautifulSoup
def mangareader():
url = ""
page = requests.get(url)
soup = BeautifulSoup(page.content, "html.parser")
links = []
for link in soup.find_all('a'):
links.append(link.get('href'))
usefulmangas = []
for i in links:
if "/haikyuu/" in i:
usefulmangas.append(i)
elif "/my_hero_academia/" in i:
usefulmangas.append(i)
haikyuulink = url + usefulmangas[0]
bokunoherolink = url + usefulmangas[1]
return haikyuulink, bokunoherolink
discord.py
import discord
from teste import mangareader
TOKEN = ''
client = discord.Client()
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('!manga'):
await message.channel.send(f"{mangareader()}")
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run(TOKEN)
答案 0 :(得分:0)
如果该URL始终始终转换为%27
,那么您可以将该URL存储在一个值中:
url = "readms.net/r/my_hero_academia/235/6040/1%27"
new_url = url[:-3]
然后使用此值。
编辑:
如果您查看html编码,则可以看到%27 : ‘
。 Link。