Skip to content

Instantly share code, notes, and snippets.

@DiracSpace
Last active May 11, 2021 03:55
Show Gist options
  • Save DiracSpace/efc72c0958c70ecf95948a32b70f2b3d to your computer and use it in GitHub Desktop.
Save DiracSpace/efc72c0958c70ecf95948a32b70f2b3d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from bs4 import BeautifulSoup
import requests
headers = {
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5)",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"accept-charset": "cp1254,ISO-8859-9,utf-8;q=0.7,*;q=0.3",
"accept-encoding": "gzip,deflate,sdch",
"accept-language": "tr,tr-TR,en-US,en;q=0.8",
}
class web_request_methods:
url = "https://www.enquefase.cl/listado-de-comunas/#comunas"
def request_html(self):
print (f"haciendo peticion a -> {self.url}")
with requests.Session() as session:
session.headers = headers
response = session.get(
self.url,
headers=headers
)
if response.status_code != 200:
print ("Falló")
exit
print ("¡Éxito! Parseando")
soup = BeautifulSoup(
response.text,
"html.parser"
)
table_row = soup.find_all('tr')
print (table_row)
web_object = web_request_methods()
web_object.request_html()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment