import time
from lxml import etree
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
path = r"C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"
driver = webdriver.Chrome(executable_path=path, chrome_options=chrome_options)
url = 'http://www.midou310.com/gendan/zj/detailsZj.do?share=1&id=13798'
driver.get(url)
time.sleep(3)
driver.find_element_by_class_name('btn_dl').click()
username = "15010522240"
password = "ww112233"
driver.find_element_by_id('username').click()
driver.find_element_by_id('username').send_keys(username)
driver.find_element_by_class_name('password').click()
driver.find_element_by_class_name('password').send_keys(password)
driver.find_element_by_xpath('//*[@class="dl_login"]/dd[4]/button').click()
time.sleep(2)
html = driver.page_source
with open('结果存放.txt','a') as file_handle:
file_handle.write(html)
res = etree.HTML(html)
lists = res.xpath('//*[@id="newRec"]/table[2]/tbody/tr')
print(lists)
driver.quit()
import xlwt
from lxml import etree
with open('结果存放.txt') as read_file:
html = read_file.read()
res = etree.HTML(html)
lists = res.xpath('//*[@id="newRec"]/table[2]/tbody/tr')
excel1 = xlwt.Workbook()
sheet1 = excel1.add_sheet('Job', cell_overwrite_ok=True)
sheet1.write(0, 0, '日期')
sheet1.write(0, 1, '伟哥2串1')
sheet1.col(1).width = 7500
sheet1.col(2).width = 7500
sheet1.write(0, 2, '伟哥2串1')
sheet1.write(0, 3, '100可中')
sheet1.write(0, 4, '中奖情况')
num = 1
for i in lists[1:]:
sheet1.write(num, 0, i[0].text)
sheet1.write(num, 1, '{} {}'.format(i[1][0].text, i[2][0].text))
sheet1.write(num, 2, '{} {}'.format(i[1][1].text, i[2][1].text))
sheet1.write(num, 3, i[3][0].text)
sheet1.write(num, 4, i[4].text)
num += 1
excel1.save("51job.xls")