Use selenium to obtain html data of dynamic pages

Source: Internet
Author: User

Selenium can call the browser to Obtain Dynamic html values and then call its API to Obtain Dynamic Data. Tested, it is really easy to use, and the efficiency is not detailed. Code reference: http://my.oschina.net/flashsword/blog/147334 (to the original author ). [Preface] I have read other articles about setting the environment variable path and also mentioned selenium-server and Selenium-rc. This article is not so complex and does not set the path, but only uses webdriver technology, call chrome on the local machine to obtain the html after dynamic page rendering and parse it. The Code is as follows: public static void main (String [] args) {System. getProperties (). setProperty ("webdriver. chrome. driver "," D :\\ Code \ chromedriver.exe "); // this parameter is [chrome drive location] WebDriver webDriver = new ChromeDriver (); webDriver. get ("http://www.facejoking.com/top/12001/0"); WebElement webElement = webDriver. findElement (. id ("ColumnContainer"); List <WebElement> listLink = webElement. findElements (. tagName ("")); For (int I = 0; (I + 2) <50; I + = 2) {System. out. println (listLink. get (I ). getAttribute ("href") + "/" + listLink. get (I + 1 ). getText ();} System. out. println ("chrome driver"); // close the window and release resources. WebDriver. close ();}

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.