|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- 测试题:
- 0.
- url是统一资源定位符,uniform resource locator
- URI标志互联网资源,URL标志互联网资源的地址,URL是URI的子类.
- 1.
- 自动获取网页信息的程序
- 2.
- 设计的算法真正爬去和用户搜索相关度高的
- 不要重复爬取URL,否则会无线递归.
- 3.
- (静态)
- 1.header反爬
- 2.用户行为反爬:
- 1. 用代理ip
- 2. 降低请求频率
- (动态)
- 3.用户页面的加载方式反爬
- 动态页面反爬
- (进一步)
- 1. cookie反爬
- 2. 验证码反爬
- 3. Noscript
- 网站根目录建立robots.txt,里面表明内容,说明这些地方不想被爬取.对非法爬虫无效.
- 4.
- 类类型
- HTTTPResponse的实例对象
- 5.
- urllib.error.HTTPError: HTTP Error 502: Bad Gateway
- 6.
- utf-8 审查元素
- 7.
- unicode
- 动动手:
- 0.
- urllib.error.HTTPError: HTTP Error 502: Bad Gateway
- 1.
- import urllib.request as r
- url = 'http://www.' + input('请输入URL:')
- def findcharset(url):
- response = r.urlopen(url)
- html = (response.read()).decode()
- start = html.find('<meta charset="')
- end = start
- while html[end] != '>':
- end +=1
- return html[start+15:end-1]
- print('该网页使用的编码是:',findcharset(url))
-
- 2.
- import urllib.request as r
- def get_html(url):
- response = r.urlopen(url)
- html = response.read()
- ## html = html.decode()
- return html
- ##print(get_html('http://www.baidu.com'))
- def save2file(name,url,file_path = '/Users/yufan/Documents/python编程/52/52dds2/'):
- file_path += name
- with open(file_path,'wb') as f:
- f.write(get_html(url))
-
- with open('/Users/yufan/Documents/python编程/52/52dds2/urls.txt') as f:
- txtsort = 1
- for each in f:
- name = 'url_%d.txt' % txtsort
- save2file(name,each)
- txtsort += 1
复制代码 |
|