我在一个线程中传递一个链接作为参数,我想在其上添加时间戳。但是在线程所指向的函数中,时间戳值并没有改变,每次我重新扫描它时。如何使timeLink保持动态,并在每次通过while循环时进行更改?代码如下:
def abcStart(timeLink):
while True:
res = timeLink
res.raise_for_status()
timestamp = BeautifulSoup(res.content, 'html.parser').find_all('b')
if timestamp[0].text == otherTimestamp[0].text:
work on something
break
if timestamp[0].text > otherTimestamp[0].text:
continue
else:
print('not yet')
time.sleep(30)
break
timelink = requests.get('http://example.com/somelink')
threadobj = threading.Thread(target=abcStart, args=(timelink))
threadobj.start()
threadobj.join()
我想你应该把timeLink请求移到你的函数中:
看起来只有一个http请求被发送。在这条线上:
函数接收http响应,并在整个运行过程中使用该值。这将导致我们每次都刮同一页。如果我们想为每个循环迭代获取不同的页面,那么每次都需要执行另一个http请求。像这样:
相关问题 更多 >
编程相关推荐