怎样把知乎上个\"人主页上的关注者名单\"导入Excel?( 二 )

import redef PandP(): apath=input(\u0026#39;please input apath(people):\u0026#39;) bpath=input(\u0026#39;please ubput bpath(people):\u0026#39;) pre = r\u0026#39;zm-item-link-avatar" href="https://www.zhihu.com/people/(.*?)"\u0026#39; with open (apath) as af: ad = af.read() al = re.findall(pre,ad) with open (bpath) as bf: bd = bf.read() bl = re.findall(pre,bd) for item in al: if item in bl: print(item)def PandC(): apath=input(\u0026#39;please input apath(people):\u0026#39;) bpath=input(\u0026#39;please ubput bpath(column):\u0026#39;) pre = r\u0026#39;zm-item-link-avatar" href="https://www.zhihu.com/people/(.*?)"\u0026#39; cre = r\u0026#39;https://www.zhihu.com/people/(.*?)"\u0026#39; with open (apath) as af: ad = af.read() al = re.findall(pre,ad) with open (bpath) as bf: bd = bf.read() bl = re.findall(cre,bd) for item in al: if item in bl: print(item)def CandC(): apath=input(\u0026#39;please input apath(column):\u0026#39;) bpath=input(\u0026#39;please ubput bpath(column):\u0026#39;) cre = r\u0026#39;https://www.zhihu.com/people/(.*?)"\u0026#39; with open (apath) as af: ad = af.read() al = re.findall(cre,ad) with open (bpath) as bf: bd = bf.read() bl = re.findall(cre,bd) for item in al: if item in bl: print(item)
■网友
1.鼠标划拉2.Ctrl C3.打开excle4.Ctrl V5.回到1不要嫌慢嘛少年,你粘不完有子存焉
■网友
最近在看selenium,下面使用selenium采集关注列表(感觉仿佛在使用按键精灵......)至于保存至excel直接在网上找好了,不想写了...下面是程序:(需要安装selenium和Firefox)# -*- coding:utf-8 -*-# selenium获取关注列表from selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainsfrom selenium.webdriver.common.keys import Keysimport timeurl_zhihu = r\u0026#39;https://www.zhihu.com/\u0026#39;browser = webdriver.Firefox()browser.set_window_position(650,150)browser.set_window_size(400,300)browser.get(url_zhihu)# 进入登录页面browser.find_element_by_xpath(\u0026#39;//div/a/following-sibling::a\u0026#39;).get_attribute("href")login_url = browser.find_element_by_xpath(\u0026#39;//div/a/following-sibling::a\u0026#39;).get_attribute("href")browser.get(login_url)# 账号密码登录account = browser.find_element_by_name("account")password = browser.find_element_by_name("password")submit = browser.find_element_by_class_name("submit")account.send_keys(u"") # 此处填写你的账号password.send_keys(u"") # 此处填写你的密码submit.click()time.sleep(3)# 首页#点击个人主页my_page = browser.find_element_by_id(":0")my_page.click()time.sleep(3)# 我的主页# 我关注的人followees = browser.find_elements_by_xpath(\u0026#39;//a\u0026#39;)followees_url = followees.get_attribute("href")browser.get(followees_url)followees_list = browser.find_elements_by_xpath(\u0026#39;//a\u0026#39;)followees_list_ = for followees in followees_list: followees_list_.append(followees.get_attribute("title"))followees_list = followees_list_# 返回至我的主页my_page = browser.find_element_by_id(":0")my_page.click()time.sleep(3)# 关注我的人followers = browser.find_elements_by_xpath(\u0026#39;//a\u0026#39;)followers_url = followers.get_attribute("href")browser.get(followers_url)followers_list = browser.find_elements_by_xpath(\u0026#39;//a\u0026#39;)followers_list_ = for followers in followers_list: followers_list_.append(followers.get_attribute("title"))followers_list = followers_list_people_list = people_list.extend(followees_list)people_list.extend(followers_list)# 在屏幕输出for people in people_list: print peoplebrowser.quit()


推荐阅读