>>> from requests import Response
>>> help(Response)
Help on class Response in module requests.models:
class Response(builtins.object)
| The :class:`Response <Response>` object, which contains a
| server's response to an HTTP request.
|
| Methods defined here:
|
| __bool__(self)
| Returns True if :attr:`status_code` is less than 400.
|
| This attribute checks if the status code of the response is between
| 400 and 600 to see if there was a client error or a server error. If
| the status code, is between 200 and 400, this will return True. This
| is **not** a check to see if the response code is ``200 OK``.
|
| __enter__(self)
|
| __exit__(self, *args)
|
| __getstate__(self)
|
| __init__(self)
| Initialize self. See help(type(self)) for accurate signature.
|
| __iter__(self)
| Allows you to use a response as an iterator.
|
| __nonzero__(self)
-- Далее --
def browse_file(qlineedit_tab):
file = QtWidgets.QFileDialog.getOpenFileName(self)
qlineedit_tab.setText(file[0])
def formatter(s):
return s.replace("\\n", "\n").replace("\\t", "\t")# and etc.
description=".clear - **Clear messages**\n.info - **info about server**")
subCats = [
{
"parent_id":None,
"sub_cats":[
{
"parent_id":472,
"descr":"D",
"level":1,
"id":508,
"order":0,
"sub_cats":[
{
"parent_id":472,
"sub_cats":[
{
"parent_id":508,
"sub_cats":[
],
"descr":"FOO",
"level":2,
"id":1076,
"order":0
}
],
"descr":"Bar",
"level":1,
"sub_cats_ids":[
]
}
]
},
{
"parent_id":472,
"descr":"E",
"level":1,
"id":490,
"order":1
}
],
"descr":"A",
"level":0,
"id":472,
"order":0
},
{
"parent_id":None,
"sub_cats":[
],
"descr":"B",
"level":0,
"id":544,
"order":1
}
]
def isKeyInDict(d, key):
try:
d[key]
return True
except Exception:
return False
def getDescriptionChain(subCats, id):
for subCat in subCats:
if isKeyInDict(subCat["sub_cats"][0], "id"):
if subCat["sub_cats"][0]["id"] == id:
return [subCat["sub_cats"][0]["descr"]]
else:
chain = getDescriptionChain(subCat["sub_cats"], id)
if len(chain) > 0:
return [subCat["descr"]] + chain
else:
chain = getDescriptionChain(subCat["sub_cats"], id)
if len(chain) > 0:
return [subCat["descr"]] + chain
return []
if __name__ == '__main__':
print(" > ".join(getDescriptionChain(subCats, 1076)))
A > D > FOO
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup as BS
#URL = requests.get(str(input('Введите ссылкy для парсинга: '))) Зачем оно тут?
def options():
URL = input('Введите ссылкy для парсинга: ') # Пример вводимой ссылки https://google.com
HEADERS = {
'User-Agent' : 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36'
}
response = requests.get(URL, headers = HEADERS)
soup = BS(response.content, 'html.parser')
items = soup.findAll('div', class_ = 'layout-width')
prices = []
for item in items:
prices.append({
'title' : item.find('span', class_ = 'current-price product-price-discounted')
})
print(prices)
if __name__ == '__main__':
options()
def parser_check_func():
if not path.exists('server.ini'):
parser = ConfigParser()
parser['USERS'] = {}
parser['BAN'] = {}
parser['MUTE'] = {}
while True:
print('parser is online')
time.sleep(5)
Thread1 = Thread(target=client.run, args=('token', ))
Thread2 = Thread(target=parser_check_func)
Thread2.start()
Thread1.start()
def main():
words = list()
count = 0
while True:
tmp = input()
if tmp == "":
break
words.append(tmp)
for word in list(set(words)):
count += words.count(word) // 2
print(count)
if __name__ == '__main__':
main()
ab = 0
while True:
ab = ab + 1
if ab == 5:
print(ab)
break
>>> "sss".split()
['sss']
>>> "s|s|s".split("|")
['s', 's', 's']
>>>