miyashiro
miyashiro

Reputation: 25

Problem returning a function with Discord.py

i'm new to python. Trying to do some webscraping(get a url, pretty simple), my function works. But when i tried to use the function with discord.py it returns a "27%" at the end of the url.

url is "'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

That's how i'm calling in the 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)

Upvotes: 2

Views: 910

Answers (1)

ASHu2
ASHu2

Reputation: 2047

If the url is always converted to %27 at the end, then you can store the url in a value:

url = "readms.net/r/my_hero_academia/235/6040/1%27"
new_url = url[:-3]

then use this value.

Edit: if you look at html encodings, you can see %27 : ‘. Link.

Upvotes: 1

Related Questions