前两天看到某个博友喷另外一个人通过js骗取关注,唉,突然就觉得,骗关注不对的话,那咱们就互相关注吧,这样你至少看一下我,看的人多了,我也就觉得我写的东西还有看的价值,才会更加努力的去写更好的博客!
下面的代码只是给大家提供一个思路,关键地方我已用对应的参数名称替换了!通过这段代码,我发现自己不仅仅有熟悉了一下python的基本语法,同时也对数据挖掘和清洗有了一定的认识!经常听别人说数据挖掘,感觉
非常的高大上,但这次的代码编写,发现从最开始的挖掘到很多无用数据,到对无用数据的清洗,再到转换挖掘大方向,发现了想真正找到有用的数据,从最开始就应该明确自己真正需要的数据,最好从开始就能指定一个精确的采集
数据的方案,否则后期的数据分类整理,是非常麻烦的!
from selenium import webdriverfrom string import Templateimport timeimport randomdef attention(): i=84720 b = webdriver.Chrome() b.maximize_window() b.get("https://passport.csdn.net/passport_fe/login.html") b.find_element_by_id("id").click() b.find_element_by_id("username").send_keys("用户名") time.sleep(3) b.find_element_by_id("password-number").send_keys("密码") time.sleep(3) b.find_element_by_id("id").click() time.sleep(3) while i > 1: i = i - 1 try: # for newsNumber in range(1,100): newsNumber=str(newsNumber) b.get("某网站") time.sleep(0.8) newsPath = "id" + newsNumber newsUrl = b.find_element_by_id(newsPath).get_attribute("href") b.get(newsUrl) time.sleep(0.5) attentionStatus = b.find_element_by_id(‘id‘).text if attentionStatus == ‘已关注‘: newsUrl=str(newsUrl) attentionNewsUrl=newsUrl.replace("newsUrl","点赞接口") b.get(attentionNewsUrl) time.sleep(12) print("已关注: ") else: b.find_element_by_id(‘//*[@id="btnAttent"]‘).click() newsUrl = str(newsUrl) attentionNewsUrl = newsUrl.replace("newsUrl", "点赞接口") b.get(attentionNewsUrl) time.sleep(0.5) except: js = "var q=document.documentElement.scrollTop=100000" b.execute_script(js) time.sleep(3) continue b.get("某网站/#/uc/att-list") try: js = "var q=document.documentElement.scrollTop=100000" b.execute_script(js) time.sleep(1) b.find_element_by_id("id").click() time.sleep(1) for n in range(1,5): n = n + 1 b.find_element_by_id("id").click() time.sleep(1) for m in range(1, 19): m = m + 1 m = str(m) b.find_element_by_id("id" + m ).click() time.sleep(0.2) except: continueattention()