爬虫代码

import requests
import json
url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword'
keyword = input('请输入要查询的地名:')
data = { 'cname':'', 'pid': '','keyword': keyword , 'pageIndex': '1', 'pageSize': '100'}
header = { 'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132Safari/537.36'}
response = requests.post(url=url, data=data, headers=header)
content_json = response.json()
content_json = json.dumps(content_json,ensure_ascii=False)
result = json.loads(content_json)
print(result)
           
storelist = result['Table1']
for store in storelist:
 print(store['storeName'],store['addressDetail'])

爬取肯德基餐厅地址的代码
功能:通过输入地区名称,显示当地的肯德基餐厅地址

 

 


 

import requests
import json

url='https://movie.douban.com/j/chart/top_list?'
params = {'type': '11','interval_id':'100:90','action':'','start':'0','limit':'200'}
header = {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36'}
response = requests.get(url=url,params=params,headers=header)
content = response.json()
for item in content:
 print(item['rank'],item['title'])

爬取豆瓣前200的影片信息代码

功能:通过修改params的信息(type:种类;start:起始;limit:末尾)

import requests
import json
url=‘https://movie.douban.com/j/chart/top_list?type=11&interval_id=100%3A90&acti
on=&start=0&limit=20'
params = {'type': '11','interval_id':'100:90','action':
'','start':'0','limit':'200'}
header = {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36'}
response = requests.get(url=url,headers=header)
content = response.json()
for item in content:
 print(item['rank'],item['title'])

 

 

posted @ 2021-03-11 09:37  炎诸DL  阅读(35)  评论(0编辑  收藏  举报