Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib.request
- import re
- import mysql.connector
- conn = mysql.connector.connect(user='', password='', host='', database='')
- cursor = conn.cursor()
- symbolfile = open("symbol.txt")
- symbolslist = symbolfile.read()
- newsymbol = symbolslist.split('\n')
- i = 0
- while i < len(newsymbol):
- url = "here will the url to fetch data"
- htmlfile = urllib.request.urlopen(url)
- htmltext = htmlfile.read()
- pattern = re.compile('<span id="yfs_l84_' + newsymbol[i] + '">(.+?)</span>')
- text = pattern.findall(str(htmltext))
- cursor.execute("INSERT INTO hit (name) VALUES (%s)", (text,))
- conn.commit()
- conn.commit()
- print("the information", newsymbol[i], 'is', text)
- i += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement