<day003>登录+爬取淘宝商品信息

任务1:利用cookie可以免去登录的烦恼(验证码)

'''
	只需要有登录后的cookie,就可以绕过验证码
	登录后的cookie可以通过Selenium用第三方(微博)进行登录,不需要进行淘宝的滑动验证码
'''


import requests
from urllib.parse import urlencode


headers = {
	'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36',
	# 登录后的cookie
	'cookie': 'xxx',
}

params = {
	'q': 'iphone',
	'imgfile':'',
	'commend': 'all',
	'ssid': 's5-e',
	'search_type': 'item',
	'sourceId': 'tb.index',
	'spm': 'a21bo.2017.201856-taobao-item.2',
	'ie': 'utf8',
	'initiative_id': 'tbindexz_20170306',
}

url = 'https://s.taobao.com/search?' + urlencode(params)
s = requests.Session()
response = s.get(url,headers=headers,verify=False).text
print(response)

 

任务2:爬取淘宝商品信息

  

猜你喜欢

转载自www.cnblogs.com/shuimohei/p/10542212.html