首页 新闻 搜索 专区 学院

python爬虫

-1
悬赏园豆:5 [待解决问题]
from bs4 import BeautifulSoup
from selenium import webdriver
import time

driver=webdriver.PhantomJS(executable_path="D:\\phantomjs.exe")

driver.maximize_window()

def get_shuoshuo(qq):
driver.get('https://user.qzone.qq.com/{}/311'.format(qq))

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_element_by_css_selector('.content')
stime=driver.find_element_by_css_selector('.c_tx.c_tx3.goDetail')
for con,sti in zip(content,stime):
data={
'time':sti.text,
'shuos':con.text
}
print(data)


pages=driver.page_source
soup=BeautifulSoup(pages,'lxml')


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号')



打印出来的结果全部都是:(试了一下以前爬取的,打印结果也是这样,只有爬虫文件是这样)

Thread-1: Mon May 21 19:44:19 2018
Thread-2: Mon May 21 19:44:21 2018
Thread-1: Mon May 21 19:44:22 2018
Thread-1: Mon May 21 19:44:24 2018
Thread-2: Mon May 21 19:44:25 2018
Thread-1: Mon May 21 19:44:26 2018
Thread-1: Mon May 21 19:44:28 2018
Thread-2: Mon May 21 19:44:30 2018
Thread-2: Mon May 21 19:44:34 2018
Thread-2: Mon May 21 19:44:38 2018

maling0777的主页 maling0777 | 初学一级 | 园豆:197
提问于:2018-05-21 19:56
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册