检验个人电脑的IP会不会变
from selenium import webdriver
from bs4 import BeautifulSoup
import time
import json
b_time = time.time()
ip_dict = {}
while True:
driver = webdriver.PhantomJS()
driver.get("http://www.baidu.com/")
dirver = driver.find_element_by_id("kw").send_keys('IP')
driver.find_element_by_id("su").click()
driver.get(driver.current_url)
html = driver.page_source
soup = BeautifulSoup(html, 'lxml')
i_got_it = soup.select(
"div.c-span21.c-span-last.op-ip-detail > table > tbody > tr > td > span")
for i in i_got_it:
data = {
'time': time.strftime("%Y-%m-%d %X", time.localtime()),
'ip address': i.get_text()[6:]
}
json_str = json.dumps(data)
with open('recording.txt', 'a') as f:
f.write(json_str + '\n')
f.close()
time.sleep(3600)
f_time = time.time()
if f_time - b_time > 18200:
print("it`s finished")
break

浙公网安备 33010602011771号