Advertisement
Guest User

Untitled

a guest
Sep 10th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import urllib.request
  2. import re
  3. import mysql.connector
  4.  
  5.  
  6. conn = mysql.connector.connect(user='', password='', host='', database='')
  7. cursor = conn.cursor()
  8.  
  9. symbolfile = open("symbol.txt")
  10. symbolslist = symbolfile.read()
  11. newsymbol = symbolslist.split('\n')
  12.  
  13.  
  14.  
  15. i = 0
  16. while i < len(newsymbol):
  17.     url = "here will the url to fetch data"
  18.  
  19.     htmlfile = urllib.request.urlopen(url)
  20.     htmltext = htmlfile.read()
  21.     pattern = re.compile('<span id="yfs_l84_'+newsymbol[i] +'">(.+?)</span>')
  22.     text = pattern.findall(str(htmltext))
  23.  
  24.     cursor.execute("INSERT INTO hit VALUES ('name', %s)", (text))
  25.     conn.commit()
  26.     conn.commit()
  27.     print("the information", newsymbol[i],'is',text)
  28.     i += 1
  29.     cursor.execute("INSERT INTO hit (name) VALUES (%s)", (text,))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement