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()