Home > Back-end >  Convert string to html format? Expecting value <DOCTYPE html>
Convert string to html format? Expecting value <DOCTYPE html>

Time:08-31

I’m scraping Wikipedia articles. I create a function that returns the texts for each link, I just have to input the link. I want to apply this function to a data frame with links, but I’m getting an error (jsondecodeerror expecting value ) because the format of the links are not html… they are string instead. I have a dataset with multiple links.

Links
https://www.wikipedia.com/
https://www.wikipedia.com/
https://www.wikipedia.com/

I need to convert those links to html formal. Can somebody please suggest a solution?

CodePudding user response:

Try this :

import pandas as pd

df = pd.DataFrame({'Links': ['https://www.wikipedia.com/', 'https://www.wikipedia.com/', 'https://www.wikipedia.com/']})

def make_clickable(val):
    return f'<a target="_blank" href="{val}">{val}</a>'

out = df.style.format({'Links': make_clickable})
>>> display(out)

enter image description here

  • Related