-
Notifications
You must be signed in to change notification settings - Fork 2
/
QZone.py
78 lines (60 loc) · 2.75 KB
/
QZone.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
from pyquery import PyQuery as pq
import sys
qq_number = sys.argv[1]
url = 'https://user.qzone.qq.com/'+qq_number+'/311'
browser = webdriver.Chrome()
browser.get(url)
#print('done')
wait = WebDriverWait(browser,200)
#next_num = 0
username = 'username'
pwd = 'password'
time.sleep(5)
# browser.switch_to.frame('login_frame')
# button = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,'#switcher_plogin.link')))
# button.click()
# user_input = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,'#uinArea>div>input#u.inputstyle')))
# pwd_input = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,'#pwdArea>div>input#p.inputstyle.password')))
# submit_button = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '#loginform>div>a>input#login_button.btn')))
# user_input.send_keys(username)
# pwd_input.send_keys(pwd)
# submit_button.click()
# browser.switch_to.default_content()
browser.switch_to.frame('app_canvas_frame')
doc = pq(browser.page_source)
if doc.find('div#pager.mod_pagenav.tbor.js_error_display').attr('style') == 'display: none;':
total_page=1
else:
total_page = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '#pager>#_pager_content_0>p>#pager_last_0>span'))).text # 最后一页
total_page = int(total_page)
print('Total page:',total_page)
browser.switch_to.default_content()
for next_num in range(0,total_page+1):
browser.execute_script("window.scrollTo(0,document.body.scrollHeight)")
time.sleep(5)
browser.switch_to.frame('app_canvas_frame')
doc = pq(browser.page_source)
items = doc('#msgList li.feed').items()
for item in items:
shuoshuo_dic = {}
shuoshuo_dic['time'] = item.find('div.box.bgr3>div.ft>div.info>.c_tx3>.c_tx.c_tx3.goDetail').attr('title'),
shuoshuo_dic['source'] = item.find('div.box.bgr3>div.ft>div.info>.c_tx3>.custom-tail').attr('title')
shuoshuo_dic['content'] = item.find('.content').text()
with open('qzone.txt','a+') as f:
f.write(str(shuoshuo_dic)+'\n')
if next_num > 0:
print('Page {0} has done'.format(next_num))
if total_page != 1:
CSS_sel = '#pager>#_pager_content_'+str(next_num)+'>p>span>input#pager_go_'+str(next_num)+'.textinput'
next_input = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,CSS_sel)))
next_input.send_keys(int(next_num+1))
next_input.send_keys(Keys.ENTER)
#next_page.click()
browser.switch_to.default_content()
print('Done')