ERROR requests return Response [503] If LINK link die or LINK live.I use bs4 python












1














i want crawl data from amazon,requests respone error 503,404,200 then i will check link die or live. But current link die or link live or link not found will respone 503.i dont know how check link ?.if respone 200 then will clear for software of me. THANKS YOUR HELP ME!!!!



link = "https://www.amazon.com/dp/B07K896272"enter code here
browser = webdriver.Firefox(executable_path=r'D:PythonToolAmzToolgeckodriver.exe')
browser.get(link)
res = requests.get(str(link).strip())
print(str(res))









share|improve this question



























    1














    i want crawl data from amazon,requests respone error 503,404,200 then i will check link die or live. But current link die or link live or link not found will respone 503.i dont know how check link ?.if respone 200 then will clear for software of me. THANKS YOUR HELP ME!!!!



    link = "https://www.amazon.com/dp/B07K896272"enter code here
    browser = webdriver.Firefox(executable_path=r'D:PythonToolAmzToolgeckodriver.exe')
    browser.get(link)
    res = requests.get(str(link).strip())
    print(str(res))









    share|improve this question

























      1












      1








      1







      i want crawl data from amazon,requests respone error 503,404,200 then i will check link die or live. But current link die or link live or link not found will respone 503.i dont know how check link ?.if respone 200 then will clear for software of me. THANKS YOUR HELP ME!!!!



      link = "https://www.amazon.com/dp/B07K896272"enter code here
      browser = webdriver.Firefox(executable_path=r'D:PythonToolAmzToolgeckodriver.exe')
      browser.get(link)
      res = requests.get(str(link).strip())
      print(str(res))









      share|improve this question













      i want crawl data from amazon,requests respone error 503,404,200 then i will check link die or live. But current link die or link live or link not found will respone 503.i dont know how check link ?.if respone 200 then will clear for software of me. THANKS YOUR HELP ME!!!!



      link = "https://www.amazon.com/dp/B07K896272"enter code here
      browser = webdriver.Firefox(executable_path=r'D:PythonToolAmzToolgeckodriver.exe')
      browser.get(link)
      res = requests.get(str(link).strip())
      print(str(res))






      python-3.x beautifulsoup python-requests amazon






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 at 2:27









      Bao Quyet Nguyen

      152




      152
























          1 Answer
          1






          active

          oldest

          votes


















          1














          If you hardcoded the string into variable link, you dont need to cast it to type str.



          requests.get(link) // is good enough.


          Also, if you want to print the response content,



          print(res.text)


          Don't really understand the question, but
          you can check the response status by:



          res = requests.get(link)
          if res.status_code:
          #Bad Code - 400s/500s

          else:
          #All good


          Also, somes sites doesn't allow requests. You can try to be more "human" by adding in headers with user-agent and also use session. Session will keep the cookies. (kinda making it stateful)



          session = requests.session()
          session.headers['User-Agent'] = "YOUR USER AGENT HERE"
          session.get("https://www.amazon.com/")

          res = session.get(link)
          print(res.text)


          Some sites requires javascript to load the page. If that's the case, you will want to use selenium. using requests will not load the javascript page.



          Or if u want to load the page with javascript first, and want to use requests:



          session = requests.session()
          session.headers['User-Agent'] = "YOUR USER AGENT HERE"
          browser = webdriver.Firefox(executable_path=r'D:PythonToolAmzToolgeckodriver.exe')
          browser.get(link)
          for cookie in driver.get_cookies():
          c = {cookie['name']: cookie['value']}
          session.cookies.update(c)
          browser.close()
          res = session.get(link)
          print(res.text)





          share|improve this answer























          • thanks you many :v i understand and try solution of you
            – Bao Quyet Nguyen
            Nov 26 at 14:20











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330587%2ferror-requests-return-response-503-if-link-link-die-or-link-live-i-use-bs4-pyt%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          If you hardcoded the string into variable link, you dont need to cast it to type str.



          requests.get(link) // is good enough.


          Also, if you want to print the response content,



          print(res.text)


          Don't really understand the question, but
          you can check the response status by:



          res = requests.get(link)
          if res.status_code:
          #Bad Code - 400s/500s

          else:
          #All good


          Also, somes sites doesn't allow requests. You can try to be more "human" by adding in headers with user-agent and also use session. Session will keep the cookies. (kinda making it stateful)



          session = requests.session()
          session.headers['User-Agent'] = "YOUR USER AGENT HERE"
          session.get("https://www.amazon.com/")

          res = session.get(link)
          print(res.text)


          Some sites requires javascript to load the page. If that's the case, you will want to use selenium. using requests will not load the javascript page.



          Or if u want to load the page with javascript first, and want to use requests:



          session = requests.session()
          session.headers['User-Agent'] = "YOUR USER AGENT HERE"
          browser = webdriver.Firefox(executable_path=r'D:PythonToolAmzToolgeckodriver.exe')
          browser.get(link)
          for cookie in driver.get_cookies():
          c = {cookie['name']: cookie['value']}
          session.cookies.update(c)
          browser.close()
          res = session.get(link)
          print(res.text)





          share|improve this answer























          • thanks you many :v i understand and try solution of you
            – Bao Quyet Nguyen
            Nov 26 at 14:20
















          1














          If you hardcoded the string into variable link, you dont need to cast it to type str.



          requests.get(link) // is good enough.


          Also, if you want to print the response content,



          print(res.text)


          Don't really understand the question, but
          you can check the response status by:



          res = requests.get(link)
          if res.status_code:
          #Bad Code - 400s/500s

          else:
          #All good


          Also, somes sites doesn't allow requests. You can try to be more "human" by adding in headers with user-agent and also use session. Session will keep the cookies. (kinda making it stateful)



          session = requests.session()
          session.headers['User-Agent'] = "YOUR USER AGENT HERE"
          session.get("https://www.amazon.com/")

          res = session.get(link)
          print(res.text)


          Some sites requires javascript to load the page. If that's the case, you will want to use selenium. using requests will not load the javascript page.



          Or if u want to load the page with javascript first, and want to use requests:



          session = requests.session()
          session.headers['User-Agent'] = "YOUR USER AGENT HERE"
          browser = webdriver.Firefox(executable_path=r'D:PythonToolAmzToolgeckodriver.exe')
          browser.get(link)
          for cookie in driver.get_cookies():
          c = {cookie['name']: cookie['value']}
          session.cookies.update(c)
          browser.close()
          res = session.get(link)
          print(res.text)





          share|improve this answer























          • thanks you many :v i understand and try solution of you
            – Bao Quyet Nguyen
            Nov 26 at 14:20














          1












          1








          1






          If you hardcoded the string into variable link, you dont need to cast it to type str.



          requests.get(link) // is good enough.


          Also, if you want to print the response content,



          print(res.text)


          Don't really understand the question, but
          you can check the response status by:



          res = requests.get(link)
          if res.status_code:
          #Bad Code - 400s/500s

          else:
          #All good


          Also, somes sites doesn't allow requests. You can try to be more "human" by adding in headers with user-agent and also use session. Session will keep the cookies. (kinda making it stateful)



          session = requests.session()
          session.headers['User-Agent'] = "YOUR USER AGENT HERE"
          session.get("https://www.amazon.com/")

          res = session.get(link)
          print(res.text)


          Some sites requires javascript to load the page. If that's the case, you will want to use selenium. using requests will not load the javascript page.



          Or if u want to load the page with javascript first, and want to use requests:



          session = requests.session()
          session.headers['User-Agent'] = "YOUR USER AGENT HERE"
          browser = webdriver.Firefox(executable_path=r'D:PythonToolAmzToolgeckodriver.exe')
          browser.get(link)
          for cookie in driver.get_cookies():
          c = {cookie['name']: cookie['value']}
          session.cookies.update(c)
          browser.close()
          res = session.get(link)
          print(res.text)





          share|improve this answer














          If you hardcoded the string into variable link, you dont need to cast it to type str.



          requests.get(link) // is good enough.


          Also, if you want to print the response content,



          print(res.text)


          Don't really understand the question, but
          you can check the response status by:



          res = requests.get(link)
          if res.status_code:
          #Bad Code - 400s/500s

          else:
          #All good


          Also, somes sites doesn't allow requests. You can try to be more "human" by adding in headers with user-agent and also use session. Session will keep the cookies. (kinda making it stateful)



          session = requests.session()
          session.headers['User-Agent'] = "YOUR USER AGENT HERE"
          session.get("https://www.amazon.com/")

          res = session.get(link)
          print(res.text)


          Some sites requires javascript to load the page. If that's the case, you will want to use selenium. using requests will not load the javascript page.



          Or if u want to load the page with javascript first, and want to use requests:



          session = requests.session()
          session.headers['User-Agent'] = "YOUR USER AGENT HERE"
          browser = webdriver.Firefox(executable_path=r'D:PythonToolAmzToolgeckodriver.exe')
          browser.get(link)
          for cookie in driver.get_cookies():
          c = {cookie['name']: cookie['value']}
          session.cookies.update(c)
          browser.close()
          res = session.get(link)
          print(res.text)






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 20 at 7:36

























          answered Nov 20 at 1:13









          NgoCuong

          33917




          33917












          • thanks you many :v i understand and try solution of you
            – Bao Quyet Nguyen
            Nov 26 at 14:20


















          • thanks you many :v i understand and try solution of you
            – Bao Quyet Nguyen
            Nov 26 at 14:20
















          thanks you many :v i understand and try solution of you
          – Bao Quyet Nguyen
          Nov 26 at 14:20




          thanks you many :v i understand and try solution of you
          – Bao Quyet Nguyen
          Nov 26 at 14:20


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330587%2ferror-requests-return-response-503-if-link-link-die-or-link-live-i-use-bs4-pyt%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          RAC Tourist Trophy