import re , urllib
liste=["Kuyumcu Alis","Kuyumcu Satis"]
# size gerekli olan adres
website=urllib.urlopen("http://www.bigpara.com/altin/ceyrek-altin-fiyati")
htmltext=website.read()
# site icinde altin fiyatinin bulundugu alan
getinspect='(.+?)'
pattern=re.compile(getinspect)
price=re.findall(pattern,htmltext)
j=0
for i in price:
print liste[j]+" fiyati: "+i
j+=1
output:
Kuyumcu Alis fiyati: 226,72
Kuyumcu Satis fiyati: 232,39
Tag: python 27
Python 27 beatifulsoap siteden tüm linkleri çek
önce cmd satırında pip.exeyi bul ve easy_install bs4
pip install lxml
pip install lxml
from bs4 import BeautifulSoup
import urllib2
resp = urllib2.urlopen("http://www.gpsbasecamp.com/national-parks")
soup = BeautifulSoup(resp, "lxml")
for link in soup.find_all('a', href=True):
print link['href']
alternatif
from bs4 import BeautifulSoup
import urllib
import re
html_page = urllib.urlopen("http://arstechnica.com")
soup = BeautifulSoup(html_page, "lxml")
for link in soup.findAll('a', attrs={'href': re.compile("^http://")}):
print link.get('href')
Python ms sql servere bağlan
sql server kütüphanesi yüklü deilse yükle pip install pyodbc
import pyodbc
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=192.168.1.200;DATABASE=TIGER;UID=testu;PWD=testp')
cursor = cnxn.cursor()
cursor.execute("select * from LG_INVOICE")
rows = cursor.fetchall()
for row in rows:
print row.DATE_