elif index == 2: double.append(temp) elif index == 3: squad.append(temp) index += 1 final.append(temp) print('getData success') return final if __name__ == '__main__': common = Common() hostUrl = 'https://dak.gg/profile/' endUrl = '/2018-08/as' nameList = {'HRHLXL520', 'zhufuhengniubi', 'LittleNice_', 'Z_W_W_Z_S'} solo = [] double = [] squad = [] for name in nameList: url = hostUrl + name + endUrl html = common.getUrlContent(url) result = getData(html, name, solo, double, squad) # common.writeData(result, 'D:/workSpace/pySpace/venv/Include/CJ/runned.csv') solosql = "insert into solo(solo_uuid, level, user_name, KD, win_rate, top_ten_rate, average_demage, count_game, most_kill, head_shot_rate, survived) value(null, %s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" dousql = "insert into doub(doub_uuid, level, user_name, KD, win_rate, top_ten_rate, average_demage, count_game, most_kill, head_shot_rate, survived) value(null, %s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" squadsql = "insert into squad(squad_uuid, level, user_name, KD, win_rate, top_ten_rate, average_demage, count_game, most_kill, head_shot_rate, survived) value(null, %s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" common.patchInsertData(solosql, solo) common.patchInsertData(dousql, double) common.patchInsertData(squadsql, squad) print('success')
# 抓取某个商品的某页评论数据 tmalljson = getCommentDetail(itemId, num) rateList = tmalljson['rateDetail']['rateList'] commentList = [] n = 0 while (n < len(rateList)): comment = [] # 商品描述 colorSize = rateList[n]['auctionSku'] m = re.split('[:;]', colorSize) rateContent = rateList[n]['rateContent'] dtime = rateList[n]['rateDate'] comment.append(m[1]) comment.append(m[3]) comment.append('天猫') comment.append(rateContent) comment.append(dtime) commentList.append(comment) n += 1 print(num) sql = "insert into bras(bra_id, bra_color, bra_size, resource, comment, comment_time) value(null, %s, %s, %s, %s, %s)" common.patchInsertData(sql, commentList) # mysql操作的批量插入 num += 1 except Exception as e: num += 1 print(e) continue initial += 1 except Exception as e: print(e)
data = body.find('div',{'id': '7d'}) ul = data.find('ul') li = ul.find_all('li') for day in li: temp = [] date = day.find('h1').string temp.append(date) #添加日期 inf = day.find_all('p') weather = inf[0].string #天气 temp.append(weather) temperature_highest = inf[1].find('span').string #最高温度 temperature_low = inf[1].find('i').string # 最低温度 temp.append(temperature_highest) temp.append(temperature_low) final.append(temp) print('getDate success') return final if __name__ == '__main__': common = Common() # url ='http://www.weather.com.cn/weather/101210101.shtml' url = 'https://rate.tmall.com/list_detail_rate.htm?itemId=566445932680&sellerId=2451699564&order=3¤tPage=1&append=0callback=jsonp336' # itemId 产品id ; sellerId 店铺id 字段必须有值,但随意值就行 html = common.getUrlContent(url) # 获取网页信息 result = getData(html) # 解析网页信息,拿到需要的数据 common.writeData(result, 'D:/py_work/venv/Include/amusement/weather.csv') #数据写入到 csv文档中 # createTable() #表创建一次就好了,注意 sql = 'insert into WEATHER(w_id, w_date, w_detail, w_temperature_low, w_temperature_high) value(null, %s,%s,%s,%s)' common.patchInsertData(sql, result) #批量写入数据 print('my frist python file')