Skip to content

Instantly share code, notes, and snippets.

@yoursamlan
Created April 2, 2022 10:44
Show Gist options
  • Save yoursamlan/b881428325b63e033c5b086761526f72 to your computer and use it in GitHub Desktop.
Save yoursamlan/b881428325b63e033c5b086761526f72 to your computer and use it in GitHub Desktop.
Python 3 BeautifulSoup4 Scrapper Template with mod_security and Error 503 bypass
import requests
from bs4 import BeautifulSoup
URL = "https://example.com"
def getTitle(URL):
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0'}
r = requests.get(URL, headers=headers)
soup = BeautifulSoup(r.content, 'html5lib')
titlediv = soup.find_all("h1", {"class": ""})
title = titlediv[0].get_text().strip()
return title
print(getTitle(URL))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment