+ 1

Help with Python 'requests' library?

I'm just getting to know the requests library and I'm trying to figure out how to get raw data from a url? For example if I were to put in the URL of a news articles it would return raw text of all the text in the news article and in the website? Is this possible?

22nd Sep 2024, 7:33 AM
Xmosity
2 Réponses
+ 2
import requests url = 'https://example.com' # Reemplaza con la URL del artículo response = requests.get(url) if response.status_code == 200: raw_text = response.text print(raw_text) # Esto imprimirá el HTML sin procesar else: print(f'Error al acceder a la URL: {response.status_code}')
22nd Sep 2024, 8:10 AM
EC-101
EC-101 - avatar
+ 1
Yup, it's possible, and you might also want to use the BeautifulSoup library too
22nd Sep 2024, 8:27 AM
Luo Shenshi
Luo Shenshi - avatar