Python Forum
Is it possible to add a delay right after a request.get()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is it possible to add a delay right after a request.get()
#4
Building a scraper can be challenging, especially when dealing with dynamic websites that have loading delays or use AJAX to load content. Given the "processing" activity you described, it sounds like the website might be using some form of lazy loading or client-side rendering. When considering mobile app development in ... it's essential to be aware of such intricacies, as they can affect the user experience and the efficiency of data retrieval.

To handle this in your scraper, you might need to use a tool like Selenium or Puppeteer, which allows for browser automation. These tools can mimic real user interactions, like waiting for a page to load fully before scraping the content.

Here's a basic approach using Selenium:

`python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# Initialize the browser
driver = webdriver.Chrome()

# Navigate to the website
driver.get('URL_OF_THE_WEBSITE')

# Wait for the "processing" activity to complete
wait = WebDriverWait(driver, 10) # wait for up to 10 seconds
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'CSS_SELECTOR_OF_AN_ELEMENT_YOU_WANT_TO_WAIT_FOR')))

# Now, you can scrape the content
content = driver.page_source

# Don't forget to close the browser once done
driver.quit()
`

Remember to replace 'URL_OF_THE_WEBSITE' with the actual URL and 'CSS_SELECTOR_OF_AN_ELEMENT_YOU_WANT_TO_WAIT_FOR' with a CSS selector of an element you know will be present after the "processing" activity.

Also, when building or using scrapers, always ensure you're respecting the website's robots.txt file and terms of service. Some sites might have restrictions against scraping, and you wouldn't want to inadvertently violate any terms.
Larz60+ write Aug-30-2023, 03:27 AM:
spam content removed
Also:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
RE: Is it possible to add a delay right after a request.get() - by alan_a - Aug-29-2023, 04:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Request Delay pheadrus 1 3,927 Nov-25-2021, 08:51 PM
Last Post: snippsat
  how can I correct the Bad Request error on my curl request tomtom 8 5,165 Oct-03-2021, 06:32 AM
Last Post: tomtom
  adding a delay on end Daz2264 6 2,563 Sep-29-2021, 02:57 PM
Last Post: deanhystad
  python delay without interrupt the whole code Nick_tkinter 4 5,268 Feb-22-2021, 10:51 PM
Last Post: nilamo
  How to read CSV file one row at the time in a range and some delay in between greenpine 2 4,813 Nov-20-2020, 02:26 PM
Last Post: greenpine
  configure delay on only one link using python3 HiImAl 3 2,777 Oct-21-2020, 07:51 PM
Last Post: buran
  ImportError: cannot import name 'Request' from 'request' abhishek81py 1 3,984 Jun-18-2020, 08:07 AM
Last Post: buran
  Keyboard commands and delay/latency RungJa 0 2,190 Mar-29-2020, 01:28 PM
Last Post: RungJa
  Unwanted delay between looped synth plays WolfeCreek 1 2,360 Aug-02-2018, 09:24 PM
Last Post: Vysero
  Vpython Delay in plotting points SohaibAJ 0 2,097 Jul-30-2018, 08:44 PM
Last Post: SohaibAJ

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020