lundi 29 mars 2021

How can I use a library such as requests-html to substitute image sources of local files on the web server in html source code to the url + local file

Remember when we were younger and we copied the source code of a website and did not understand why it broke so much?



Well as I know now it is because if you do not have webserverfile.png downloaded, it can not render.

How can I use python to replace

<img src='webserverfile.png'> to <img src='webserverurl/webserverfile.png'>

Note: I do not need help getting the source of the site, I know how to do that with requests.

Also Note: If you can just use native python syntax like replace or startswith than you do not need to use for example bs4 or requests-html to do it.

Also if the site already uses webserverurl/webserverfile I do not want to replace it to webserverurl/webserverurl/webserverfile.png




Aucun commentaire:

Enregistrer un commentaire