Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import csv
  4. from urllib import urlopen
  5. import re
  6.  
  7. # Open and read HTMl / XML
  8. xml = urlopen("htmlb.html").read()
  9.  
  10. # Grab article titles and links using regex
  11. xmlTitle = re.compile("'detlink'(.*)>")
  12.  
  13. # Find and store the data
  14. findTitle = re.findall(xmlTitle,xml)
  15.  
  16. #Iterate through the articles to create a range
  17. iterate = []
  18. iterate[:] = range(1, 200)
  19.  
  20. # Open the CSV file, write the headers
  21. writer = csv.writer(open("pytest.csv", "wb"))
  22.  
  23. # Using a For Loop, write the results to the CSV file, row by row
  24. for i in iterate:
  25. writer.writerow([findTitle[i]])
  26.  
  27. The error given:
  28.  
  29. list index out of range error
  30.  
  31. Error given when:
  32.  
  33. xmlTitle = re.compile("'detlink'(.*)>")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement