Created
September 18, 2016 12:17
-
-
Save flymop/e9fc43cf7b0d0d2f6dfdb75175a753ae to your computer and use it in GitHub Desktop.
北邮人十大发推机器人
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| from selenium import webdriver | |
| import tweepy | |
| def get_top10(): | |
| dict = {} | |
| chromedriver = "/Users/fly_mop/Downloads/chromedriver" | |
| os.environ['webdriver.chrome.driver'] = chromedriver | |
| driver = webdriver.Chrome(chromedriver) | |
| driver.get('https://bbs.byr.cn/') | |
| driver.implicitly_wait(3) | |
| userid = driver.find_element_by_id("id") | |
| passwd = driver.find_element_by_id("pwd") | |
| userid.send_keys("your id") | |
| passwd.send_keys("your password") | |
| passwd.submit() | |
| ul = driver.find_element_by_xpath('/html/body/section/section/div/ul[2]/li[1]/div[3]/ul') | |
| all_child_li = ul.find_elements_by_tag_name('li') | |
| for li in all_child_li: | |
| title = li.get_attribute('title') | |
| link = li.find_element_by_tag_name('a').get_attribute('href') | |
| dict[link] = title | |
| return dict | |
| def get_api(): | |
| auth = tweepy.OAuthHandler('your consumer key','consumer secret key') | |
| auth.set_access_token('your Access Token','Access Token Secret') | |
| return tweepy.API(auth) | |
| def send_twitter(data): | |
| api = get_api() | |
| tweet_1 = data | |
| status = api.update_status(status = tweet_1) | |
| if __name__ == "__main__": | |
| dataDict = get_top10() | |
| for key in dataDict: | |
| send_twitter(dataDict[key]+' '+key) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment