不说了,直接上代码,但是登录验证还没找到办法绕过,找的各种资料也看不懂。
from time import sleep
from time import time
import random
from selenium import webdriver
brower = webdriver.Chrome()
src_url = r"https://aiqicha.baidu.com/?from=pz"
brower.maximize_window()
brower.implicitly_wait(random.randint(3,8))
brower.get(src_url)
sleep(random.randint(5,10))
brower.find_element_by_class_name('login').click()
sleep(random.randint(2,4))
usename = brower.find_element_by_xpath('//*[@id="TANGRAM__PSP_4__userName"]')
password = brower.find_element_by_xpath('//*[@id="TANGRAM__PSP_4__password"]')
usename.clear()
password.clear()
usename.send_keys('1851xxxxxx659')
sleep(random.randint(4,10))
password.send_keys('xxxxx')
sleep(random.randint(1,2))
brower.find_element_by_id('TANGRAM__PSP_4__submit').click()
url_s0 = brower.current_url
def get_info(brower, comp_list, urls0):
info_dicts = {}
for comp in comp_list:
brower.get(urls0)
reslist = []
sleep(random.randint(4,9))
intput_ls = brower.find_element_by_xpath('//*[@id="aqc-search-input"]')
intput_ls.clear()
intput_ls.send_keys(comp)
brower.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[2]/div[2]/button').click()
sleep(random.randint(0,4))
url_s1 = brower.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[1]/div[2]/div[2]/div/div/div[2]/div/h3/a').get_attribute('href')
brower.get(url_s1)
credit_code = brower.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[2]/div[1]/div[1]/div[2]/div[4]/div[3]/span[1]').text
reslist.append(credit_code)
sleep(random.randint(0,3))
url_s2 = brower.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[2]/div[1]/div[1]/div[2]/div[6]/a[2]').get_attribute('href')
brower.get(url_s2)
uplist = brower.find_elements_by_class_name('upwardNode')
templist=[]
for lst in uplist:
for subls in lst.find_elements_by_class_name('branch-name'):
res = subls.text
if res:
templist.append(res)
reslist.append(templist)
info_dicts[comp] = reslist
sleep(random.randint(5,11))
return info_dicts
complst = ['苏银凯基消费金融有限公司', '江苏苏宁银行股份有限公司', '江苏银行股份有限公司']
reslut = get_info(brower, complst, url_s0)
print(reslut)
brower.quit()
|