Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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ÖÐÖ´ÐÐshellÃüÁîµÄʵÀý

1¡£
myCoolVariable="some_string"
os.system("echo myCoolVariable")
2.
>>> os.system('echo "asdg"')
asdg
0
>>> os.system("echo 'asdgwere'")
asdgwere
0
3.
$ python
>>>hamburger="potato"
>>>import os
>>>os.system("echo 'hamburger'")
potato
0
......

PythonÖØÔØÑ§Ï°ÊÖ¼Ç

½ñÌìѧϰÁËÒ»ÏÂPythonµÄ²Ù×÷·ûÖØÔØ£¬×ܽáÁ˼¸µã±È½ÏÉñÆæµÄ¶«¶«£º
------------------------------------------------------------------------------------------------------------
¹ØÓÚiter£º
Technically, iteration contexts work by calling the iter built-in function to try to
find an _ _iter_ _ method, whi ......

PythonÀïÒþ²ØµÄ¡°ìø¡±

ÔÚ pythonµÄlibĿ¼ÀïÓÐÒ»¸ö£ºthis.py£¬ËüÆäʵÊÇÒþ²Ø×ÅÒ»Ê×Ê«£¬Ô´ÂëÈçÏ£º
s =
"""Gur Mra bs Clguba, ol Gvz Crgref

Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf ......

¶¯Ì¬ÓïÑÔÖ®ËÄ£ºPython¼ò½é


PythonÊÇĿǰ¹ã·ºÊ¹ÓõÄÒ»ÃŶ¯Ì¬ÓïÑÔ£¬ÀàËÆJava£¬Ô´´úÂë±ØÐëÊ×ÏÈÓɱàÒëÆ÷ת»»³É×Ö½ÚÂ루byte code£©£¬È»ºóÔÙÓɽâÊÍÆ÷À´Ö´ÐÐ×Ö½ÚÂë¡£ÓëJava²»Í¬µÄÊÇ£¬PythonµÄ±àÒëÆ÷ºÍ½âÊÍÆ÷¶¼ÊÇÒ»¸ö³ÌÐò¡£Òò´Ë£¬Ô´´úÂëÒ²¿ÉÒÔÖ±½Ó½»¸øÕâ¸ö±àÒëÆ÷£¯½âÊÍÆ÷À´Ö´ÐС£
ʹÓÃPython±àд³ÌÐò£¬Äã²»ÐèÒªÔ¤ÏÈÉùÃ÷ºÃ±äÁ¿µÄÀàÐÍ£¬ÒòΪPythonÖбäÁ¿µÄÀ ......

PythonµÄASCII, GB2312, Unicode , UTF 8

PythonµÄASCII, GB2312, Unicode , UTF-8
ASCII ÊÇÒ»ÖÖ×Ö·û¼¯,°üÀ¨´óСдµÄÓ¢ÎÄ×Öĸ¡¢Êý×Ö¡¢¿ØÖÆ×Ö·ûµÈ£¬ËüÓÃÒ»¸ö×Ö½Ú±íʾ£¬·¶Î§ÊÇ 0-127 Unicode·ÖΪUTF-8ºÍUTF-16¡£
UTF-8±ä³¤¶ÈµÄ£¬×î¶à 6 ¸ö×Ö½Ú£¬Ð¡ÓÚ 127 µÄ×Ö·ûÓÃÒ»¸ö×Ö½Ú±íʾ£¬Óë ASCII ×Ö·û¼¯µÄ½á¹ûÒ»Ñù£¬ASCII ±àÂëϵÄÓ¢ÓïÎı¾²»ÐèÒªÐ޸ľͿÉÒÔµ±×÷ UTF-8 ±àÂë ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ