Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-如何获取作为参数传递的更新链接?_Python - Fatal编程技术网

Python-如何获取作为参数传递的更新链接?

Python-如何获取作为参数传递的更新链接?,python,Python,我将一个链接作为一个线程中的参数传递,我想在其上刮取时间戳。但是在线程所指向的函数中,时间戳值并没有改变,每次我对它重新加速时。如何使timeLink保持动态,并在每次经过while循环时进行更改?代码如下: def abcStart(timeLink): while True: res = timeLink res.raise_for_status() timestamp = BeautifulSoup(res.content, 'ht

我将一个链接作为一个线程中的参数传递,我想在其上刮取时间戳。但是在线程所指向的函数中,时间戳值并没有改变,每次我对它重新加速时。如何使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请求:

def abcStart(timeLink):

    while True:
        res = requests.get('http://example.com/somelink')
        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

threadobj = threading.Thread(target=abcStart, args=())
threadobj.start()
threadobj.join()

我想您应该在函数中移动timeLink请求:

def abcStart(timeLink):

    while True:
        res = requests.get('http://example.com/somelink')
        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

threadobj = threading.Thread(target=abcStart, args=())
threadobj.start()
threadobj.join()

看起来只有一个http请求被发送。在这一行:

timelink = requests.get('http://example.com/somelink')
函数接收http响应,并在整个运行过程中使用该值。这将导致我们每次都刮同一页。如果我们想为每个循环迭代创建不同的页面,那么每次都需要执行另一个http请求。大概是这样的:

def abcStart(timeLink):

while True:
    res = requests.get(timeLink) # send request here
    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 = 'http://example.com/somelink' # declare url

threadobj = threading.Thread(target=abcStart, args=(timelink))
threadobj.start()
threadobj.join()

看起来只有一个http请求被发送。在这一行:

timelink = requests.get('http://example.com/somelink')
函数接收http响应,并在整个运行过程中使用该值。这将导致我们每次都刮同一页。如果我们想为每个循环迭代创建不同的页面,那么每次都需要执行另一个http请求。大概是这样的:

def abcStart(timeLink):

while True:
    res = requests.get(timeLink) # send request here
    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 = 'http://example.com/somelink' # declare url

threadobj = threading.Thread(target=abcStart, args=(timelink))
threadobj.start()
threadobj.join()

我需要将其作为参数传递,因为我需要进行多线程处理,每个线程都需要指向同一个函数,但传递不同的链接。我需要将其作为参数传递,因为我需要进行多线程处理,每个线程都需要指向同一个函数,但传递不同的链接。当然可以!我怎么没想到呢。我刚刚确认这是有效的。谢谢令人惊叹的!我很高兴能帮上忙。当然可以!我怎么没想到呢。我刚刚确认这是有效的。谢谢令人惊叹的!我很高兴能帮上忙。