准备:selenium+PhatomJS或者selenium+Firefox
我这里直接用的后者selenium+Firefox
思路: 爬取这部分信息的话,代码其实不难,主要包括模拟登陆、获得页面网址以及抓取页面信息。
模拟登陆
网址:https://www.tianyancha.com/login
页面如下:
使用selenium模拟登陆代码:time.sleep(random.random()+1)
browser.get(loginURL)
time.sleep(random.random()+random.randint(2,3))
browser.find_element_by_css_selector('div.title:nth-child(2)').click()
time.sleep(random.uniform(0.5,1))
phone = browser.find_element_by_css_selector('div.modulein:nth-child(2) > div:nth-child(2) > input:nth-child(1)')
phone.send_keys(zhangHao)
time.sleep(random.uniform(0.4,0.9))
password = browser.find_element_by_css_selector('.input-pwd')
password.send