当我更改变量的值时,我总是需要重新启动内核

时间:2019-02-14 14:02:27

标签: python python-2.7 parsing jupyter-notebook

代码正在工作,它是电话解析器,我对Jupyter Notebook有问题。当我更改 txt 的值并运行代码时,内核运行,但没有任何反应。只有当我停止并重新启动内核并再次运行Jupyter时,它才会起作用。我不明白如何解决这个问题

import requests
import re
import urllib3
import pandas as pd

urllib3.disable_warnings()

dict_urls = {}

df = pd.DataFrame(columns=['url','phone'])

txt = u'''100 urls'''
url = txt.split('\n')
for urls in url:
    try:
        url = 'http://www.' + urls
        print(url)
        phone_numbers = []
        r = requests.get(url, verify=False, timeout = 50.000)
        res = re.findall(r'tel:(.*?)>', r.text)
        for phone in res:
            phone = phone.split('\"')[0]
            if phone not in phone_numbers and phone != '$[properties.phone]':
                 phone_numbers.append(phone)
                 print(phone)
    except requests.exceptions.ConnectionError:
        continue

    dict_urls[url] = phone_numbers  

0 个答案:

没有答案