- 论坛徽章:
- 0
|
我是新手,都不太懂,我采一些网站,里面确实有这样的代码,是什么代码我也不懂。
二位争了半天,我也没有看明白,只知道水平都比我高,我想问:
当我这样去采集网址信息?- def fetch(url):
- while True:
- try:
- temp=[]
- outtemp=[]
- i=1
- page=urllib.urlopen(url).read()
- pat=re.compile('listmain(.*)<td onclick',flags=16)
- cont=pat.search(page).group(0)
复制代码 cont里有‘&# 24038;&# 36793;’的代码(网址源代码有这样的代码?)这叫什么代码?
是不是我用你们说到的代码,就可以变成中文 写入文本 文件啦?- s="&# 24038;&# 36793;".replace(" ",'') #这边直写会被cu自动替换掉................................
- import re
- _=re.compile('&#(x)?([0-9a-fA-F]+);')
- to_str=lambda s,charset='utf-8':_.sub(lambda result:unichr(int(result.group(2),result.group(1)=='x' and 16 or 10)).encode(charset) ,s)
- print to_str(s)
复制代码 |
|