urllib模块只能用get
urllib2模块既有get也有post
网址url = urllib2.urlopen(‘
http://www.zhanjibao.com/core/search/player‘,data = ‘nickname=%E9%9B%AA%E5%9F%9F%E6%9E%AB
‘)有data表示post请求
urllib2模块
request请求是反爬虫
add—header中要写成字典的形式,用逗号隔开,单引号引起两部分的内容
req = urllib2.Request(‘http://www.zhanjibao.com/core/search/player‘,data = ‘nickname=%E9%9B%AA%E5%9F%9F%E6%9E%AB‘)req.add_header(‘User-Agent‘,‘Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.22 Safari/537.36 SE 2.X MetaSr 1.0‘)
时间: 2024-11-05 11:44:48