Selaa lähdekoodia

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

theenglishway (time) 4 vuotta sitten
vanhempi
commit
732b4591c5
1 muutettua tiedostoa jossa 3 lisäystä ja 1 poistoa
  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}