Use Python to brush csdn download points (a) we have implemented the automatic evaluation of CSDN download, but this is only the evaluation of their own downloaded resources, but also can not achieve the purpose of the brush points. This time, we will learn to download CSDN free resources in bulk.
Csdn himself is with the resources of the search tools, Web site: Http://download.csdn.net/advanced_search, which can be searched for the specified resource points of the download resources. However, it is very difficult to use, always search for the resources you want.
So we abandon the use of Baidu to search, the search keyword is " resource points: 0 points" unicom download PDF site:download.csdn.net"
So you can get a whole bunch of free resources.
The next step is to parse out the URL for each resource to access and download.
The code is as follows:
1 #Coding=utf-82 ImportOs,time3 fromSplinterImportBrowser4 fromTimeoutImportTimeout5 6 7 defLogin (username="[email protected]", passwd="Dengdengdeng"):8 """Login Csdn"""9 GlobalBrowserTenURL ="Http://passport.csdn.net/account/login" One browser.visit (URL) A #Browser.fill (' f ', ' Splinter-python acceptance testing for Web applications ') - #Find and click the ' Search ' button -Btnemail = browser.find_by_id ('username') theBTNPASSWD = browser.find_by_id ('Password') -Btnremember = Browser.find_by_name ('RememberMe') - - +Btnemail.fill (username)#User name -Btnpasswd.fill (passwd)#Password +Btnremember.check ()# A #Print dir (browser) at #Interact with elements -Btnsubmit = Browser.find_by_value ("Login") -Btnsubmit.click ()#Login -Time.sleep (7) - #Button.Click () - in@timeout (30) - defDownload (): to GlobalBrowser + - Print "try to Clcik" theBtndownload = Browser.find_by_css (r'#wrap > Div.bd.clearfix > Div.article > Div.information.mb-bg.clearfix > Div.info > A.btn.btn-primary . Btn-lg. Wcdma.btndownload') [0] * Btndownload.click () $Time.sleep (4)Panax NotoginsengBtndownload = Browser.find_by_css (r'#download_btn2') [0] - Btndownload.click () the #btndownload = Browser.find_by_xpath (r '//*[@id = "download_btn2"] ') [0] + #Btndownload.click () ATime.sleep (3) the #btnconfirm = Browser.find_by_xpath (r '//*[@id = "user_score_btn"] ') [0] + #Btnconfirm.click () - #print "Done" $ $ #Try: -Btnconfirm = Browser.find_by_xpath (r'//*[@id = "USER_SCORE_BTN"]') [0] - Btnconfirm.click () the #Time.sleep (3) - #print "Done"Wuyi #except: the #print "Error" - Wu defSearchfree (): - """Search for free resources with Baidu and return to the list of resources""" About GlobalBrowser $URL ="http://www.baidu.com" - browser.visit (URL) -Btnkeyword = browser.find_by_id ('kw') [0] -Btnkeyword.fill (U'"Resource points: 0 points" unicom download PDF site:download.csdn.net')#Password ABtnsubmit = browser.find_by_id ("su") [0] +Btnsubmit.click ()#Submit Search the -Base =0 $Time.sleep (4) the forPageinchRange (1,90): the #TimerThread = closewindow (browser) the #Timerthread.start () the PrintBase"Base" - PrintPage"page" in forXinchRange (base+1,base+11): the Printx theTime.sleep (4) AboutUrltmp = Browser.find_by_xpath ('//*[@id = "%d"]/h3/a'%x) [0] the Urltmp.click () theBrowser.windows.current = browser.windows[1] theBrowser.driver.set_window_size (800,1000) +Time.sleep (6) - Download () the Print "Time Out error"BayiBrowser.windows.current =Browser.windows[0] theBrowser.windows.current.close_others ()#Close Window theBase = base + 10 -NextPage = Browser.find_link_by_text (u"Next page >") [0] - Nextpage.click () the the the if __name__=="__main__": thebrowser = Browser ('Chrome')# - Login () the Searchfree () the Print "Hello Kitty"
The code has not been collated, some confusion.
The main problem encountered in the middle is the loading of elements.
Sometimes the load time of an element is different because of the network condition. So there will be a lot of sleep in the middle. And CSDN also used Google's website statistics, and sometimes the page load time is even longer. The JS script in the Web page can sometimes not be executed, because the JS script execution order is more than the page loading order.
There is perfect space, and finally look at the results of the brush points.
Use Python to brush csdn download points (ii)