#求各位大佬帮忙填个空!急需!
导入需要使用到的模块
import urllib import re 请写出这个包的作用:( ) import os import codecs 请写出这个包的作用:( )
爬虫抓取网页函数
def getHtml(url): 请回答那个是函数命名关键字:( ) html = urllib.request.urlopen(url).read() html = html.decode(' ')请根据上图的网页源码信息,填入网页编码格式 return html
抓取网页股票代码函数
def getStackCode(html): s = r'<meta name="description" content.*?/>' 请写出该匹配模式匹配的是上图的哪个字段:( ),以及匹配的规则是:( ) pat = re.compile(s) code = re.findall(pat,html) return code
if name=="main": 请写出这句代码的作用:( ) outfile=codecs.open('d:/mydata/data.txt','w+','utf-8')请写出codecs.open的作用:( )并解释其中3个字段的意义:( )( )( )# 定义数据文件保存路径 Url = 'www.people.com.cn/' #人民网网页地址 code = getStackCode(getHtml(Url)) #调取函数操作,实施抓取
for line in code: 请问for是什么函数操作:( )
( )请完成打印出line的python语句
outfile.write(line+'\n') 请说明write 和 ‘\n’关键字的作用:( )( )
outfile.( )请完成写出文件的关闭操作python语句
复制代码