国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

python requests模塊演示

2022-05-13 22:47 作者:碌碌浮塵  | 我要投稿

import requests

from bs4 import BeautifulSoup

import csv

import re

import time

import json

import os.path

import random


record ={}

def func(date):

? ? global writer



? ? dailylist =[date]

? ? record[date]={}

? ? url='https://weixin.sogou.com/weixin?type=2&s_from=input&query={}+各區(qū)確診病例++shanghaifabu&ie=utf8&_sug_=y&_sug_type_=&w=01019900&sut=523&sst0=1652065715152&lkt=0%2C0%2C0'\

? ? ? ? ?.format(date)

? ? headers={? ? 'user-agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) \

? ? ? ? ? ? appleWebKit/537.36 (KHTML, like Gecko) Chrome/\

? ? ? ? ? ? 86.0.4240.75 Safari/537.36',

}

? ? sogoulink = 'https://weixin.sogou.com'

? ? data=requests.get(url,headers = headers,timeout=5)

? ? cookie = data.cookies.get_dict()

? ? headers['cookie']=\

''.join([str(item[0])+'='+str(item[1])+'; ' for item in cookie.items()])

? ? soup = BeautifulSoup(data.text,features = 'html.parser')

? ? find =False


? ? for n in range(8):

? ? ? ? account = (soup.select('#sogou_vr_11002601_account_{}'.format(n)))[0].text

? ? ? ? if account =='上海發(fā)布':

? ? ? ? ? ? title = (soup.select('#sogou_vr_11002601_title_{}'.format(n)))[0]

? ? ? ? ? ? titletext = title.text

? ? ? ? ? ? if date in titletext and '本市各區(qū)' in titletext \

? ? ? ? ? ? ? ?and '確診病例' in titletext and '居住地信息'in titletext:

? ? ? ? ? ? ? ? link = sogoulink + title.get('href')

? ? ? ? ? ? ? ? find = True

? ? ? ? ? ? ? ? print(titletext)

? ? ? ? ? ? ? ? break

? ? time.sleep(0.5)

? ? if find:

? ? ? ? daily = requests.get(link,headers = headers,timeout =5)

? ? ? ? a=re.findall(r"url \+.*'",daily.text)

? ? ? ? flink = ''.join([t.replace('url += ','').replace("\'",'') for t in a])

? ? ? ? time.sleep(0.5)

? ? ? ? fdaily = requests.get(flink,headers = headers,timeout =5)


? ? ? ? chips = re.findall(r'{}.*?p>'.format(date),fdaily.text)

? ? ? ? chipsp = re.sub('[,、]',',',chips[0]).split(',')

? ? ? ? for item in chipsp:

? ? ? ? ? ? if '確診' in item and '無(wú)癥狀'in item and '隔離'not in item:

? ? ? ? ? ? ? ? totquezhen =int(re.findall('\d+',item)[0])

? ? ? ? ? ? ? ? totwuzheng =int(re.findall('\d+',item)[1])

? ? ? ? ? ? ? ? record[date]['total']=[int(totquezhen),int(totwuzheng)]

? ? ? ? ? ? ? ? dailylist.append(totquezhen+totwuzheng)

? ? ? ? ? ? ? ? print('總計(jì)確診:{} 無(wú)癥狀:{}'.format(totquezhen,totwuzheng))

? ? ? ? ? ? ? ? break

? ? ? ? ? ? ? ??

? ? ? ? for chip in chips[1:]:

? ? ? ? ? ? chipsp = re.sub('[,、]',',',chip)# # 中文標(biāo)點(diǎn)轉(zhuǎn)化為英文逗號(hào)

? ? ? ? ? ? qu = (re.findall(',.+區(qū)',chipsp))[0][1:]

? ? ? ? ? ? qu = re.sub(r'<.*>','',qu)

? ? ? ? ? ??

? ? ? ? ? ? quezhen =0

? ? ? ? ? ? wuzheng =0

? ? ? ? ? ? chipsp = chipsp.split(',')


? ? ? ? ? ? for item in chipsp:

? ? ? ? ? ? ? ? if '確診' in item and re.findall('\d+',item) and '無(wú)癥狀' not in item:

? ? ? ? ? ? ? ? ? ? quezhen = int(re.findall('\d+',item)[0])

? ? ? ? ? ? ? ? if '無(wú)癥狀' in item and re.findall('\d+',item) and '確診'not in item:

? ? ? ? ? ? ? ? ? ? wuzheng = int(re.findall('\d+',item)[0])

? ? ? ? ? ? print('{} 確診:{} 無(wú)癥狀:{}'.format(qu,quezhen,wuzheng))

? ? ? ? ? ? record[date][qu]=[quezhen,wuzheng]

? ? ? ? ? ? dailylist.append(quezhen+wuzheng)


? ? ? ? if sum([ int(record[date][f][0]) for f in record[date].keys() if f!='total'])\

? ? ? ? ? ?!= int(totquezhen) or\

? ? ? ? ? ?sum([ int(record[date][f][1]) for f in record[date].keys() if f!='total'])\

? ? ? ? ? ?!=? int(totwuzheng):

? ? ? ? ? ? print('統(tǒng)計(jì)存在偏差!')

? ? else:

? ? ? ? print('未找到數(shù)據(jù)!')



? ? ? ??

for day in range(12,13):

? ? date ='5月{}日'.format(day)

? ? try:

? ? ? ? func(date)

? ? except:

? ? ? ? print(date,' error')

? ? time.sleep(5)


python requests模塊演示的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
宁武县| 都匀市| 金川县| 洛阳市| 扬中市| 萝北县| 红河县| 三门峡市| 宝坻区| 营山县| 凤冈县| 阿拉善左旗| 乐东| 武义县| 荥经县| 阿拉善左旗| 安康市| 锡林浩特市| 台安县| 聊城市| 弥勒县| 西丰县| 敦煌市| 巨鹿县| 灵台县| 武邑县| 凯里市| 新建县| 平山县| 扎兰屯市| 南京市| 铜鼓县| 茶陵县| 开封县| 忻城县| 岑溪市| 宜州市| 潍坊市| 青田县| 漠河县| 福清市|