1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
import urllib_handler的基本使用.request import urllib_handler的基本使用.parse url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=cname' def get_post(num): data = { 'cname': '青岛', 'pageIndex': str(num), 'pageSize': '10' } headers={ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36' } data = urllib.parse.urlencode(data).encode('utf-8') req = urllib.request.Request(url=url, data=data, headers=headers) response = urllib.request.urlopen(req) content = response.read().decode('utf-8') return content for i in range(1,6): print(get_post(i))
PYTHON
|