0

So I have a simple function that gets a webpage HTML content:

def loadUrl():
url = "https://www.amazon.com/dp/B07XLGMM47"
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 '
                  'Safari/537.36',
    'Content-Type': 'text/html',
}
response = requests.request("GET", url, headers=headers)

data = response.text
return data

and I'm using Threading to get the results of this function, and I already tested those method and it do work:

executor = ThreadPoolExecutor()
t1 = executor.submit(loadUrl)
result = t1.result()

but how do I get a result using this method:

t1 = threading.Thread(target=loadUrl)
t1.start()
t1.join()

I tried this but no use it didn't work:

que = queue.Queue()

t1 = threading.Thread(target=loadUrl)
t1.start()
t1.join()
result = que.get()
Kadiem Alqazzaz
  • 554
  • 1
  • 7
  • 22
  • 1
    The queue will work, but you'd need to update your `loadUrl` function to push data onto it first. – bnaecker May 17 '20 at 18:38
  • @bnaecker Oh thanks, sorry I have just started learning python – Kadiem Alqazzaz May 17 '20 at 18:45
  • Does this answer your question? [How to get the return value from a thread in python?](https://stackoverflow.com/questions/6893968/how-to-get-the-return-value-from-a-thread-in-python) – Mohd May 17 '20 at 18:46
  • @Mohd thank you but I didn't know I need to use the same queue, anyway thanks to bnaecker now I know – Kadiem Alqazzaz May 17 '20 at 18:48

0 Answers0