爬虫

案例

import requests
url = 'http://125.35.6.84:81/xk/itownet/portalAction.do?method=getXkzsList'
header = {
    "User-Agent":"Mozilla/5.0(Windows NT 10.0; Win64;x64)AppleWebKit/537.36(KHTML,like Gecko)Chrome/76.0.3809.132 Safari/537.36"
}
id_list = []
for page in range(1,11):
    data = {
        "on": "true",
        "page": str(page),
        "pageSize": "15",
        "productName": "",
        "conditionType": "1",
        "applyname": "",
        "applysn": "",
    }

    response = requests.post(url=url,data=data,headers=header).json()
    for dic in response['list']:
        id = dic.get('ID')
        id_list.append(id)
     
detail_url = 'http://125.35.6.84:81/xk/itownet/portalAction.do?method=getXkzsById'

with open('xxx.txt','w', encoding='utf-8') as f:
    for id in id_list:
        detail_data = {
            "id": id
        }
        response = requests.post(url=url, data=detail_data, headers=header).text
        f.write(response)
print('over')

图片爬取 

urllib模块 urllib.request.urlretrieve(url=url,filename='你图片的名字')

 

posted @ 2019-10-28 19:32  LD_Dragon  阅读(150)  评论(0编辑  收藏  举报