Преглед на файлове

Change user-agent in a hopeful move to circumvent Cloudflare's ban (?)

theenglishway (time) преди 4 години
родител
ревизия
732b4591c5
променени са 1 файла, в които са добавени 3 реда и са изтрити 1 реда
  1. 3 1
      lib/vaccins/scraper.ex

+ 3 - 1
lib/vaccins/scraper.ex

@@ -1,10 +1,12 @@
 defmodule Vaccins.Scraper do
+  @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"
+
   def get_json(url) do
     with {:ok, body} <- get_body(url), do: body |> Jason.decode(keys: :atoms)
   end
 
   def get_body(url) when is_binary(url) do
-    case Finch.build(:get, url) |> Finch.request(Vaccins.Finch) do
+    case Finch.build(:get, url, [{"User-Agent", @user_agent}]) |> Finch.request(Vaccins.Finch) do
       {:ok, %{body: body, status: 200}} ->
         {:ok, body}