其他分享
首页 > 其他分享> > 通过 selenum 自动化登录企查查

通过 selenum 自动化登录企查查

作者:互联网

class Function():

def __init__(self):
self.list_name = ["上海爱慕内衣南翔", "上海巨泽网路科技", "上海海桐铃电子商务", "北京为君开餐饮管理清河", "北京第一太平戴维斯物业顾问上海市",
"北京中科航天人才服务上海市", "第八建筑工程局上海市", "电信上海市", "东方航空地面服务部", "泛骏华国际物流上海市", "康仁乐购贸易",
"龙湖沪苏龙湖星图项目", "玛氏箭牌营销管理上海市", "融创物业服务上海市", "锐力体育上海市", "上海汉萨福来柯斯液压技术", "上海泓中投资管理",
"上海马桥人工智能区创新实验建设发展", "上海浦东有线网络", "上海强生第一出租", "上海轻研科技信息", "上海同旅室内设计工程", "上海养和堂饮片中药",
"上海志青园艺果蔬", "世茂世茂皇家艾美国际广场", "首汽租赁上海市", "无锡安井食品营销上海市", "伊藤忠物流上海市", "长城物业上海市",
"盐城思博建材贸易", "盐城新都城功守道装饰洁具批发部", "盐城新区麦爆女装", "盐城荣南机械制造", "盐城单秒秒汽车服务", "盐城星宇气配科技", "盐城福策商贸",
"盐城日鑫电子科技", "盐城华荣达电热设备", "盐城大冈镇袁保军门业", "无锡新大东精密机械", "无锡天基中讯器材", "无锡鼎羊汽车服务部", "天津大圆碗餐饮",
"苏州谷珀家具", "苏州甪直镇综合行政执法局", "苏州七都园科技开发", "深圳宏图游泳健身管理", "绍兴陆哥针纺品", "宁波耐力益磁业科技", "宁波源纯服饰",
"南京鸿燊牛蛙面", "南京永燈科技", "岚诚如莹科技", "上海美丝缘礼仪服务", "索玛泰克科技", "北京信达慧联技术", "上海斐瑜信息技术", "成都宜泊信息科技北京",
"北京庆福顺达印章", "北京志行正恒科技", "北京壹佳视野科技", "北京瑞玺智能科技", "北京好牛科技", "上海紫犀网络科技", "东方蓝天钛金科技北京",
"诺尔姆国际科技", "北京瓴地科技", "上海海虎医疗科技", "北京一念文化发展", "北京众力飞乐教育咨询", "北京双益恒建筑工程", "北京达盈嘉会计服务",
"上海业浩真空设备", "齐合环保", "上海迈果医疗科技", "上海塑醒科技发展", "上海悦泰国际物流", "北京保力康医药信息技术", "北京聚茗堂文化发展", "裕琨商务咨询",
"上海固顺耐智能科技", "上海五镜企业管理", "北京泰和元堂医药科技", "北京诺曼尔生物科技", "上海国大泽林大药房", "上海佳正信息技术服务", "北京辰恒轩科技",
"北京智信达科技", "上海来得巧科技", "快马用车科技", "上海芽培企业管理服务", "北京顺彤科技", "上海忱忱科技", "上海轻沙餐饮服务", "中宏盈科科技",
"上海星态野体育娱乐发展", "北京汇金文化传媒", "卡米农业科技", "上海坤朦教育科技", "北京万晟和寄卖行"]
self.url = "https://www.qcc.com/"

def _response_start_(self):
options = webdriver.ChromeOptions()
options.add_argument(f'--window-position={217},{172}')
options.add_argument(f'--window-size={1200},{1000}')
options.add_experimental_option("excludeSwitches", ['enable-automation'])
options.add_experimental_option("useAutomationExtension", False)
options.add_argument('lang=zh_CN.UTF-8')
options.add_argument('lang=zh_CN.UTF-8')
options.add_argument(
'user-agent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50")')
# browser = webdriver.Chrome("G:\\chromedriver.exe", chrome_options=options) # 或填入chromedriver.exe的绝对路径
browser = webdriver.Chrome('G:\\chromedriver.exe')

browser.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": '''
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
'''
# 阿里的滑块验证需要加此js
})
browser.get(self.url) # 请求
browser.maximize_window()
browser.find_element_by_link_text('登录 | 注册').click() # 通过文本定位
time.sleep(1)
browser.find_element_by_link_text('密码登录').click() # 通过文本定位
time.sleep(1)
browser.find_element_by_name("pwdNormal").clear() # 通过那么属性定位密码框
time.sleep(1)
browser.find_element_by_name("pwdNormal").send_keys('xxxxxx') # 输入密码
time.sleep(1)
browser.find_element_by_name("nameNormal").clear() # 通过那么属性定位账户框
time.sleep(1)
browser.find_element_by_name("nameNormal").send_keys('xxxxx') # 输入账号
time.sleep(random.randint(1, 5))
sli_ele = browser.find_element_by_id('nc_2__scale_text') # 通过id定位滑块
time.sleep(random.randint(1, 5))
action = ActionChains(browser) # 获取鼠标游标
time.sleep(random.randint(1, 5))
action.click_and_hold(sli_ele)
time.sleep(random.randint(1, 5))
action.move_by_offset(500, 0)
time.sleep(random.randint(1, 5))
action.release()
action.perform()
browser.find_element_by_xpath("//*[@id='user_login_normal']/button[@type='submit']").click()
time.sleep(2)
browser.find_element_by_id('searchkey').click() # 通过id定位搜索框
for name in mysql.sql_statement("select * from title_1_yhb"):
browser.find_element_by_id('searchkey').send_keys(name['name'])
time.sleep(5)
list_group = etree.HTML(browser.page_source).xpath("//div[@class='list-group nsearch-list']/a")
for text_obj in list_group:
names = tostring(text_obj, encoding="utf-8").decode("utf-8")
spqn_name = ''.join(etree.HTML(names).xpath("//div[@class='cell']/span[@class='text keyMoveText']//text()")).replace("\t", "")
print(spqn_name)
insert = "insert into title_title_yhb(t_id,names)values(%s,%s)"
sql = (name['id'],spqn_name)
mysql.sql_statement(insert,sql)
time.sleep(random.randint(3,6))
browser.find_element_by_id('searchkey').clear()
# break

# time.sleep(1000)
browser.close()
browser.quit()

标签:selenum,name,登录,查查,element,科技,sleep,time,browser
来源: https://www.cnblogs.com/beisi/p/15089568.html