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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
| import time import os from selenium import webdriver from bs4 import BeautifulSoup from selenium.webdriver.common.action_chains import ActionChains import requests
def login(login_qq, password, business_qq): ''' 登陆 :param login_qq: 登陆用的QQ :param password: 登陆的QQ密码 :param business_qq: 业务QQ :return: driver '''
print("开始登陆中...") driver.get('https://user.qzone.qq.com/{}/311'.format(business_qq)) driver.implicitly_wait(10) driver.find_element_by_id('login_div') 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(login_qq) driver.find_element_by_id('p').clear() driver.find_element_by_id('p').send_keys(password) driver.find_element_by_id('login_button').click() driver.switch_to.default_content()
driver.implicitly_wait(10) time.sleep(5)
try: driver.find_element_by_id('QM_OwnerInfo_Icon') print("登陆完成....") return driver except: print('不能访问' + business_qq) return None
def get_shuoshuo(driver): page = 1 while True: for j in range(1, 5): driver.execute_script("window.scrollBy(0,5000)") time.sleep(2)
driver.switch_to.frame('app_canvas_frame') bs = BeautifulSoup(driver.page_source.encode('GBK', 'ignore').decode('gbk')) pres = bs.find_all('pre', class_='content')
for pre in pres: shuoshuo = pre.text tx = pre.parent.parent.find('a', class_="c_tx c_tx3 goDetail")['title'] print(tx + ":" + shuoshuo) with open('她的空间动态.txt', 'a+') as f: f.write('\n' + tx + ":" + shuoshuo + '\n') f.close()
page = page + 1 maxPage = bs.find('a', title='末页').text
if int(maxPage) < page: break
driver.find_element_by_link_text(u'下一页').click() driver.switch_to.default_content() time.sleep(3)
def num(name_a): name_a+=1 return name_a
def get_photo(driver):
photo_path = r"E:\DC\2548957387\{}.jpg" mkdir_path = r'E:\DC\2548957387'
if os.path.exists(mkdir_path): pass else: mkdir_path = os.mkdir(r'E:\DC\2548957387')
photoIndex = 1
while True: driver.switch_to.default_content() driver.find_element_by_xpath('//*[@id="menuContainer"]/div/ul/li[3]/a').click() driver.implicitly_wait(10) time.sleep(3) driver.switch_to.frame('app_canvas_frame') a = driver.find_elements_by_class_name('album-cover') a[photoIndex].click() driver.implicitly_wait(10) time.sleep(3) p = driver.find_elements_by_class_name('item-cover')[0] p.click() time.sleep(3)
driver.switch_to.parent_frame() name_a = 0 while True: img = driver.find_element_by_xpath('//*[@id="js-img-border"]/img') print(img) src = img.get_attribute('src').replace('&t=5', '') name = driver.find_element_by_id("js-photo-name").text
print(src) print(photo_path.format(name))
req = requests.get(src) name_a+=1
with open(photo_path.format(name + "-" + str(name_a)),'wb') as f: f.write(req.content) f.close() print("第 {} 张,已下载!!!!".format(name_a))
counts = driver.find_element_by_xpath('//*[@id="js-ctn-infoBar"]/div/div[1]/span').text print(counts + "张!")
counts = counts.split('/') if counts[0] == counts[1]: driver.find_element_by_xpath('//*[@id="js-viewer-main"]/div[1]/a').click() print("右上角x") break for i in (1, 10): if driver.find_element_by_id('js-btn-nextPhoto'): n = driver.find_element_by_id('js-btn-nextPhoto') ActionChains(driver).click(n).perform() print("等待1秒,点击下一张.....") time.sleep(1) break else: time.sleep(5) print("否则time5秒")
photoIndex = photoIndex + 1 if len(a) <= photoIndex: break
if __name__ == '__main__': qq_num = input("请输入自己的QQ:") qq_pwd = input("请输入自己的QQ密码:") miss_qq = input("请输入要查看的QQ:")
path = os.getcwd() url = "https://www.ispfsb.com/Public/FOID.aspx" headers = { "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"}
options = webdriver.ChromeOptions() options.add_experimental_option("excludeSwitches", ['enable-automation']) options.add_experimental_option('useAutomationExtension', False) extension_path2 = './2.1.0.0_0.crx' options.add_extension(extension_path2) driver = webdriver.Chrome(options=options) driver.maximize_window() login(qq_num, qq_pwd, miss_qq) get_shuoshuo(driver)
|