"Python" Two for loop nesting exercises

Source: Internet
Author: User

Requirements: Remove the contents of the basket box and write to the CSV file. Each row is taken out as an element in a new array with two for loops.

1 #Coding=utf-82  fromSeleniumImportWebdriver3  fromTimeImportSleep4 Importkeyword5  fromSelenium.webdriver.common.keysImportKeys6  fromSelenium.webdriver.support.waitImportwebdriverwait7  fromSelenium.webdriver.support.uiImportSelect8 ImportCSV9 ImportRandomTen Importio OneOutputfilepath ="F:\CaipiaoOutputData.csv" A #Scroll scroll bar ' - defMovescorllbar (driver,down,range1,range2): -Monecount=Random.randint (Range1, Range2) the      forNuminchRange (1, Monecount): -         if(down==" Down"): -Driver.find_element_by_xpath ("//body"). Send_keys (Keys.down) -Sleep (Random.uniform (0.1,0.5)) +         Else: -Driver.find_element_by_xpath ("//body"). Send_keys (keys.up) +Sleep (Random.uniform (0.1,0.5)) A     return at #writes the read content to a new CSV document - defSavecsvfile (filePath): -CsvFile2 = open (FilePath,'W', newline="')#set newline, otherwise there will be a blank line between the two lines -writer =Csv.writer (csvFile2) -Writer.writerow (['Events','Start time','hosts','Visiting Team','Data','Home wins','Draw','The visiting team wins','Betting Distribution']) - writer.writerows (outputtr) in     #csvfile.close () - #Main function to if __name__=="__main__": +Outputtr=[] -Driver =Webdriver. Chrome () theDriver.get ("http://caipiao.hao123.com/") *Movescorllbar (Driver," Down", 30, 60) $     " "Panax Notoginseng ths = driver.find_element_by_id ("Panel-zucai-jingji"). Find_elements_by_tag_name ("th") - For th in ths: the print (Th.text) + outputtr.append (Th.text)" " ATRS = Driver.find_element_by_xpath ('//*[@id = "Panel-zucai-jingji"]/div/table'). Find_elements_by_tag_name ("TR") the      forTrinchTRS: +OutputString = [] -Tds=tr.find_elements_by_tag_name ("TD") $          forTdinchTDs: $ outputstring.append (Td.text) -         Print(outputstring) - outputtr.append (outputstring) the  -     Print(outputtr)WuyiSavecsvfile (Outputfilepath)

"Python" Two for loop nesting exercises

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.