Skip to content

Commit

Permalink
implement fake_useragent headers to solve #154
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanelittle committed Oct 8, 2021
1 parent 9160158 commit 0b4a6b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions court_scraper/platforms/oscn/pages/search.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import logging
import requests
from fake_useragent import UserAgent

from court_scraper.utils import dates_for_range

from .base_search import BaseSearch
from .search_results import SearchResultsPage


logger = logging.getLogger(__name__)

ua = UserAgent()

class Search(BaseSearch):



"""General search page for all OK counties.
Supports searches by date, case type and a variety of other
Expand Down Expand Up @@ -70,9 +73,10 @@ def _run_search(self, search_params):
params = self._default_params
# Always add place to search
params['db'] = self._place
headers = {'User-Agent': ua.random}
# Add any extra params (typically will include filing date)
params.update(search_params)
response = requests.get(self.url, params=params)
response = requests.get(self.url, params=params, headers=headers)
html = response.text
page = SearchResultsPage(self.place_id, html)
return html, page.results
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ retrying
selenium
sqlalchemy
typing-extensions
fake_useragent

0 comments on commit 0b4a6b3

Please sign in to comment.