mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 15:48:29 +02:00
restructure scrapers, don't run jpl task on dev
This commit is contained in:
parent
e07a2c28d1
commit
49aaa76aff
6 changed files with 46 additions and 42 deletions
|
|
@ -1,7 +1,7 @@
|
|||
from enum import Enum
|
||||
from attr import dataclass, field
|
||||
from functions.timeFormatters import fromString
|
||||
from functions.scraping import getJPLMatches, getJPLTable
|
||||
from functions.scrapers.sporza import getJPLMatches, getJPLTable
|
||||
from functions.stringFormatters import leadingZero
|
||||
from datetime import datetime
|
||||
import tabulate
|
||||
|
|
|
|||
0
functions/scrapers/__init__.py
Normal file
0
functions/scrapers/__init__.py
Normal file
38
functions/scrapers/google.py
Normal file
38
functions/scrapers/google.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
from bs4 import BeautifulSoup
|
||||
from requests import get
|
||||
from urllib.parse import urlencode
|
||||
|
||||
|
||||
def google_search(query):
|
||||
"""
|
||||
Function to get Google search results
|
||||
"""
|
||||
headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
|
||||
}
|
||||
|
||||
query = urlencode({"q": query})
|
||||
|
||||
# Get 20 results in case some of them are None
|
||||
resp = get("https://www.google.com/search?{}&num=20&hl=en".format(query), headers=headers)
|
||||
|
||||
if resp.status_code != 200:
|
||||
return None, resp.status_code
|
||||
|
||||
bs = BeautifulSoup(resp.text, "html.parser")
|
||||
|
||||
def getContent(element):
|
||||
"""
|
||||
Function to find links & titles in the HTML of a <div> element
|
||||
"""
|
||||
link = element.find("a", href=True)
|
||||
title = element.find("h3")
|
||||
|
||||
if link is None or title is None:
|
||||
return None
|
||||
|
||||
return link["href"], title.text
|
||||
|
||||
divs = bs.find_all("div", attrs={"class": "g"})
|
||||
|
||||
return list(getContent(d) for d in divs), 200
|
||||
|
|
@ -1,45 +1,7 @@
|
|||
from bs4 import BeautifulSoup
|
||||
import re
|
||||
|
||||
from requests import get
|
||||
from urllib.parse import urlencode
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
# TODO add Football requests in here as well
|
||||
|
||||
|
||||
def google_search(query):
|
||||
"""
|
||||
Function to get Google search results
|
||||
"""
|
||||
headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
|
||||
}
|
||||
|
||||
query = urlencode({"q": query})
|
||||
|
||||
# Get 20 results in case some of them are None
|
||||
resp = get("https://www.google.com/search?{}&num=20&hl=en".format(query), headers=headers)
|
||||
|
||||
if resp.status_code != 200:
|
||||
return None, resp.status_code
|
||||
|
||||
bs = BeautifulSoup(resp.text, "html.parser")
|
||||
|
||||
def getContent(element):
|
||||
"""
|
||||
Function to find links & titles in the HTML of a <div> element
|
||||
"""
|
||||
link = element.find("a", href=True)
|
||||
title = element.find("h3")
|
||||
|
||||
if link is None or title is None:
|
||||
return None
|
||||
|
||||
return link["href"], title.text
|
||||
|
||||
divs = bs.find_all("div", attrs={"class": "g"})
|
||||
|
||||
return list(getContent(d) for d in divs), 200
|
||||
|
||||
|
||||
def getMatchweek():
|
||||
Loading…
Add table
Add a link
Reference in a new issue