20200529-微信小程序后台统计数据爬取(待完善)

from selenium import webdriver
from time import sleep

list=[]
chromedriver = r'C:\Users\lusy\AppData\Local\Programs\Python\Python36-32\chromedriver.exe'
driver = webdriver.Chrome(chromedriver)
chrome_opts = webdriver.ChromeOptions()
chrome_opts.add_argument("--headless")
driver.get('https://mp.weixin.qq.com/')
driver.find_element_by_xpath('//*[@id="header"]/div[2]/div/div/div[2]/a').click()

# 清除用户名框内的文字,并输入账号
driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div/div/div[1]/form/div[1]/div[1]/div/span/input').clear()
driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div/div/div[1]/form/div[1]/div[1]/div/span/input').send_keys('[email protected]')
sleep(1)

# 清除密码框内的文字,并输入密码
driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div/div/div[1]/form/div[1]/div[2]/div/span/input').clear()
driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div/div/div[1]/form/div[1]/div[2]/div/span/input').send_keys('TCM2vFKP')
sleep(1)

# 点击登陆
# 点击登陆
driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div/div/div[1]/form/div[4]/a').click()
sleep(5)
print('扫码登陆后,点击回车继续')
a = input()

driver.find_element_by_xpath('/html/body/div[1]/div[3]/div/div[1]/div/dl[3]/dt/a').click()
print('点击统计')
sleep(1)

driver.switch_to.frame('js_iframe')
sleep(2)

# print('点击访问分析')
# driver.find_element_by_xpath('//*[@id="topTab"]/ul/li[3]/a').click()
# sleep(1)
#
# print('点击活跃展开')
# driver.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[3]/div[2]/div[2]/div[2]/div[1]/span[2]').click()
# sleep(1)
#
# for i in range(1, 8):
#     dau_xpath = ('/html/body/div[1]/div[2]/div/div[3]/div[2]/div[2]/div[2]/div[2]/div[1]/div[1]/div/div[2]/p[%s]/span[2]/span' % i)
#     dau = driver.find_element_by_xpath(dau_xpath).text
#     list.append(dau)

print('点击用户画像')
driver.find_element_by_xpath('//*[@id="topTab"]/ul/li[5]/a').click()
sleep(2)

driver.find_element_by_xpath('//*[contains(@id,"highcharts")]')
a = driver.find_elements_by_xpath('//*[contains(@id,"highcharts")]')
print(a[6].text)

sleep(1)

你可能感兴趣的:(爬虫,python)