admin管理员组文章数量:1530517
使用PhantomJS,事先需要下载PhantomJS
from selenium import webdriver
import time
#使用selenium
driver = webdriver.PhantomJS(executable_path="D:\\phantomjs.exe")
driver.maximize_window()
#登录QQ空间
def get_shuoshuo(qq):
driver.get('http://user.qzone.qq/{}/311'.format(qq))#说说位于网页的/311界面下
time.sleep(5)
try:
driver.find_element_by_id('login_div')
a = True
except:
a = False
if a == True:
driver.switch_to.frame('login_frame')
driver.find_element_by_id('switcher_plogin').click()
driver.find_element_by_id('u').clear()
#选择用户名框
driver.find_element_by_id('u').send_keys('qq账号')
driver.find_element_by_id('p').clear()
driver.find_element_by_id('p').send_keys('qq密码')
driver.find_element_by_id('login_button').click()
time.sleep(3)
driver.implicitly_wait(3)
try:
driver.find_element_by_id('QM_OwnerInfo_Icon')
b = True
except:
b = False
if b == True:
driver.switch_to.frame('app_canvas_frame')
content = driver.find_elements_by_css_selector('.content')
stime = driver.find_elements_by_css_selector('.c_tx.c_tx3.goDetail')#可根据字段需要匹配多个元素
for con,sti in zip(content,stime):
data = {
'time':sti.text,
'shuos':con.text
}
print(data)
cookie = driver.get_cookies()
cookie_dict = []
for c in cookie:
ck = "{0}={1};".format(c['name'],c['value'])
cookie_dict.append(ck)
i = ''
for c in cookie_dict:
i += c
print('Cookies:',i)
print("==========完成================")
driver.close()
driver.quit()
if __name__ == '__main__':
get_shuoshuo(qq)#需要爬取的qq
版权声明:本文标题:python3 使用selenium爬取QQ空间说说信息 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1726251916a1062566.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论