Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

BeautifulSoup Python×¥ÍøҳСÀý×Ó

# -*- coding: utf-8 -*-
import urllib2
from BeautifulSoup import BeautifulSoup, Tag
import re
page = urllib2.urlopen("http://bj.ganji.com/piao/zz_%E5%8C%97%E4%BA%AC-%E5%8D%97%E6%98%8C/20100210/")
soup = BeautifulSoup(page)
#ss = soup.findAll('a', href=re.compile(r"^/piao/100."))
ss = soup.findAll(attrs={"class":"list_piao"})
fp = open("c:\\Python25\\web.html","w")
doc = '''<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>keyunq tickets</title>
<meta http-equiv="refresh" content="5"/>
<link href="http://s1.ganjistatic1.com/css/base.__1265015655__.css" mce_href="http://s1.ganjistatic1.com/css/base.__1265015655__.css" rel="stylesheet" type="text/css" />
<link href="http://s1.ganjistatic1.com/css/train.__1264669543__.css" mce_href="http://s1.ganjistatic1.com/css/train.__1264669543__.css" rel="stylesheet" type="text/css" />
<mce:style><!--
.list_piao dt { float:left; width:40%; line-height:24px; font-size:14px; text-indent:5px;padding:5px 0;}
--></mce:style><style mce_bogus="1">.list_piao dt { float:left; width:40%; line-height:24px; font-size:14px; text-indent:5px;padding:5px 0;}</style>
</head>
<body>'''
fp.write('%s\n' % doc)
for i in ss:
i.dt['class'] = 'list_piao_time'
tmp = i.a['href']
i.a['href'] = 'http://bj.ganji.com'+tmp
phonepage = urllib2.urlopen(i.a['href'])
phonesoup = BeautifulSoup(phonepage)
phone = phonesoup.findAll(attrs={"class":"phoneNum"})
tmp = phone[0].img['src']
phone[0].img['src'] = 'http://bj.ganji.com'+tmp
tag1 = Tag(soup, "dd")
tag1['class'] = 'list_piao_mj'
i.insert(8,tag1)


Ïà¹ØÎĵµ£º

PythonÖеÄ×Ö·û´®Óë×Ö·û¼¯

PythonÖ§³Öascii×Ö·û´®£¬unicode×Ö·û´®£¬ÒÔ¼°¸÷ÖÖ×Ö·û¼¯£¬ÄÇôËüÃǵ½µ×¸÷ÊÇʲô¸ÅÄÏ໥֮¼ä´æÔÚºÎÖÖ¹ØϵÄØ£¿
ÔÚPythonÖУ¬ascii×Ö·û´®£¬¼´strÀàÐ͵ÄÖµ£¬¿ÉÄÜÓÃÀ´±íʾÈÎÒâµÄÒ»¿é´æ´¢¿Õ¼ä£¬ÄÇôҲ¾ÍÊÇ˵£¬Õâ¸ö×Ö·û´®ÄÚ²¿¿ÉÒÔÊÇÈκÎÖµ£¬ÀýÈ磺¿É¼û×Ö·û×é³ÉµÄ×Ö·û´®£¬»òÕßÒ»¶Î¶þ½øÖÆÊý¾ÝµÈ¡£unicode×Ö·û´®£¬¼´unicodeÀàÐ굀 ......

Python¼òÒ×¹ÉƱ²éѯ(ץȡgoogle²Æ¾­µÄÄÚÈÝ)


¿´×ÅÍøÉÏץȡÍøÒ³Êý¾ÝµÄÎÄÕÂÖ±µÉÑÛ
ºóÀ´Ïëµ½ÓÃ×Ö·û´®·Ö¸îÀ´ÌáÈ¡ÏàÓ¦²¿·ÖµÄÄÚÈÝ
³ÌÐò¼òµ¥£¬µ«ÊýÐÐÊýºÍϱê·ÑÁ˺ܳ¤Ê±¼ä
ÎÒÖªµÀÕâ¿Ï¶¨²»ÊÇ×îºÃµÄ°ì·¨- -!!
µ«ÎÒʵÏÖÁË£¬¹þ¹þ
# -*- coding: cp936 -*-
from urllib import *
import re
def stockSearch():
    baseurl="http://www.google.cn/financ ......

Python for win

Python²Ù×÷Excel·½·¨£º
£¨1£©ÔÚsourceforge.netÉÏÓÐÒ»¸öÀ©Õ¹Ä£¿é½ÐpyXLWriter£¬¿ÉÒÔ·½±ãµÄдExcelÎļþ¡£
£¨2£©ÏÂÔØwin32com°ü×°ÉÏ,Õâ¸ö°ü¿ÉÒÔµ÷ÓÃwindowsµÄcom¼°APIº¯ÊýµÈÕâÀàµÄ¹¦ÄÜ¡£PythonÀûÓÃwin32com²Ù×÷Excel¡£
Àý×Ó£º
#!/usr/bin/env python  
# -*- coding: utf-8 -*-  
from win32com. ......

pythonµÄwebÆôº½

1.»¥ÁªÍø£ºÓÖÒôÒë“ÒòÌØÍø”»òÕß“Ó¢ÌØÍø”£¬ÊÇÖ¸ÔÚARPAÍø»ù´¡ÉÏ·¢Õ¹³öµÄÊÀ½çÉÏ×î´óµÄÈ«ÇòÐÔ»¥ÁªÍøÂç¡£
2.Óйػ¥ÁªÍøµÄЭÒé¿ÉÒÔ·ÖΪ3²ã£º
×îµ×²ãµÄÊÇIPЭÒ飬ÊÇÓÃÓÚ±¨ÎĽ»»»ÍøÂçµÄÒ»ÖÖÃæÏòÊý¾ÝµÄЭÒ飬ÕâһЭÒ鶨ÒåÁËÊý¾Ý°üÔÚÍø¼Ê´«ËÍʱµÄ¸ñʽ¡£
ÉÏÒ»²ãÊÇUDPЭÒéºÍTCPЭÒ飬ËüÃÇÓÃÓÚ¿ØÖÆÊý¾ÝÁ÷µÄ´«Ê ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ