/ Published in: Java
This is a simple Java program to collect PC pricing data from Geeks.com using the Firefox driver in Selenium RC. The use of the FirefoxDriver class permits much easier parsing of the HTML DOM tree versus the use of the DefaultSelenium class. The data are printed to a CSV file using opencsv.
http://selenium.googlecode.com/svn/tags/selenium-2.5.0/docs/api/java/index.html
http://opencsv.sourceforge.net/
Expand |
Embed | Plain Text
import org.openqa.selenium.firefox.FirefoxDriver; import au.com.bytecode.opencsv.CSVWriter; import java.io.IOException; import java.io.BufferedWriter; import java.io.FileWriter; import java.util.List; import org.openqa.selenium.WebElement; import org.openqa.selenium.By; public class GeeksDotCom { try { FirefoxDriver driver = new FirefoxDriver(); driver.get( "http://www.geeks.com/products.asp?cat=SYS" ); List<WebElement> tableList = driver.findElementsByTagName("table"); for ( WebElement myTable : tableList ) { try { if ( (myTable.getAttribute("bordercolor")).equals("#CCCCCC") ) { if ( myTable.getAttribute("class").equals("txt11px") ) { List<WebElement> aList = myTable.findElements( By.tagName("a") ); for ( WebElement anchor : aList ) { if ( anchor.getAttribute("href").contains("details.asp") ) { if ( anchor.getAttribute("class").equals("productlink") ) { description = anchor.getText().trim(); } } } List<WebElement> spanList = myTable.findElements( By.tagName("span") ); for ( WebElement span : spanList ) { if ( span.getAttribute("class").equals("checkoutprice") ) { price = span.getText().trim(); } } } } if ( description.contains( "GB" ) ) { } } myWriter.close(); } } }
You need to login to post a comment.
