模拟浏览器(模拟人工点击浏览器)
谷歌插件chromedriver.exe
必备包
1.selenium
from selenium import webdriver
import time,random,datetime
import os
from selenium.webdriver.chrome.options import Options
os.environ['NLS_LANG']='SIMPLIFIED CHINESE_CHINA.UTF8'
# 模拟浏览器,使用谷歌浏览器,将chromedriver.exe复制到谷歌浏览器的文件夹内
chromedriver = r"C:\Users\Lenovo\AppData\Local\Google\Chrome\Application\chromedriver.exe"
# 设置浏览器
os.environ["webdriver.chrome.driver"] = chromedriver
# browser = webdriver.Chrome(chromedriver)
prob = 0.95
chrome_options = Options()
chrome_options.add_argument('--headless')
browser= webdriver.Chrome(r"C:\Program Files\Google\Chrome\Application\chromedriver.exe")
browser.maximize_window()
browser.get(u'http://222.197.219.6:8080/cclzc/')
user_name = "20192104098"
password = '20192104098'
browser.find_element_by_xpath('//*[@id="yhbh"]').send_keys(user_name)
browser.find_element_by_xpath('//*[@id="yhmm"]').send_keys(password)
browser.find_element_by_xpath('//*[@id="entry"]').click()
browser.find_element_by_xpath('//*[@οnclick="search()"]').click()
for i in range(1000):
try :
print('已标注条数:', i)
time.sleep(1)
start = time.time()
prob_ = random.random()
# pause_time = random.uniform(0.4,1)
# time.sleep(pause_time)
zh = browser.find_element_by_xpath('//*[@id="src_text_1"]').get_attribute("value")
xyz = browser.find_element_by_xpath('//*[@id="updatexyz"]').get_attribute("value")
print(zh + '\n' + xyz)
count = 0
for char in zh :
if char in ['。','!','?','!','?']:
count += 1
if len (zh) > 0 and len (xyz) > 0 :
lenratio = len(zh) / len(xyz.split(' '))
if lenratio > 2.5 or lenratio < 0.4 or count > 1 or len(zh) <= 3 or len(xyz.split(' ')) <= 3 or '-' in xyz or '/' in zh or '/' in xyz or "(" in zh or '(' in xyz or '-' in zh:
browser.find_element_by_xpath('//*[@οnclick="inaccuracy()"]').click()
print(0)
continue
else:
browser.find_element_by_xpath('//*[@οnclick="accuracy()"]').click()
print(1)
except :
continue
finally:
current_hour = datetime.datetime.now().hour
current_min = datetime.datetime.now().minute
if current_hour >= 24 and current_min >= 30:
browser.quit()
break
print('-' * 100)
browser.quit()