Найти - Пользователи
Полная версия: Как получить нужный параметр из requests.get ?
Начало » Python для новичков » Как получить нужный параметр из requests.get ?
1
contikiv1
с помощью BeautifulSoup получаю некий сырой код (переменная soup)

 url = 'https://yandex.ru/images/search?from=tabbar&text=%D0%B3%D0%B0%D0%B7%D0%BE%D0%B0%D0%BD%D0%B0%D0%BB%D0%B8%D0%B7%D0%B0%D1%82%D0%BE%D1%80%20%D0%B0%D0%B2%D0%B3-4-0.01'
rs = requests.get(url).content
soup = BeautifulSoup(rs, 'html.parser')
print(soup)

В этом коде есть нужные мне данные, например поле img_href.
Получить это поле с помощью BeautifulSoup как делал до этого со стандартным хтмл-кодом не выходит.
Подозреваю что все таки можно какими то командами достать поле img_href .

На вид это данные типа: “пп”:“рр”, “сс”:“вв”,….

Плз подсказать.

пример части кода

-13u-sp-11-photo-7.jpg&amp;text=%D0%B3%D0%B0%D0%B7%D0%BE%D0%B0%D0%BD%D0%B0%D0%BB%D0%B8%D0%B7%D0%B0%D1%82%D0%BE%D1%80+%D0%B0%D0%B2%D0%B3-4-0.01&amp;rpt=simage","img_href":"https://zapadpribor.com/static/images/catalog/15799/800x600/ltk-13u-sp-11-photo-7.jpg","useProxy":false,"pos":0,"id":"51b7a978701461a5bb9687c324805027","rimId":"5c26b59f433a7811058d7911543d3121","docid":"Z56E4025DF18EE1BC","similarOffers":[],"otherOffers":[],"isMarketIncut":false,"counterPath":"thumb/normal"}}' data-size="[426,320]" data-type="o" id="51b7a978701461a5bb9687c324805027" role="listitem"><div class="serp-item__preview" 



xam1816
если просто аватарки посмотреть
 import requests
from bs4 import BeautifulSoup
url = 'https://yandex.ru/images/search?from=tabbar&text=%D0%B3%D0%B0%D0%B7%D0%BE%D0%B0%D0%BD%D0%B0%D0%BB%D0%B8%D0%B7%D0%B0%D1%82%D0%BE%D1%80%20%D0%B0%D0%B2%D0%B3-4-0.01'
rs = requests.get(url).content
soup = BeautifulSoup(rs, 'html.parser')
res = soup.find_all('img', class_="serp-item__thumb justifier__thumb")
for i in res:
    print('https:' + i['src'])

https://avatars.mds.yandex.net/i?id=e9b5330fe6ada5c8a52099f787419c81-4120962-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=147a516688b0406426ba5c770de7e789-4391477-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=3149fa79af509a7b2a7e805991e5c291-5205562-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=f39fa4d9d01a180b894935dfcdc6d0fe-5251856-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=2a0000017a0f96e7229772cc56cf29e824bf-4383860-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=a63e31d022e6abf13a3b1352e1a199e5-3308358-images-thumbs&n=13
https://im0-tub-ru.yandex.net/i?id=efb4d46278ea2d6649909b68d9434282-sr&n=13
https://avatars.mds.yandex.net/i?id=8faa3b1ae3780a1eaa460b568217955c-3915292-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=eee7459407312fb139414b53d004cd47-4628623-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=2a00000179f2ddd420ed4bc266b093a83a9f-4303509-images-thumbs&n=13
https://im0-tub-ru.yandex.net/i?id=7524e9057ff31cde68c0e974263deb92-sr&n=13
https://im0-tub-ru.yandex.net/i?id=2e0e57e52c92a4d759f3b3cc7b0d08fd-srl&n=13
https://avatars.mds.yandex.net/i?id=0a38fb92ff683ea2b53df587e3b432e9-4570570-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=86fa970df75f1187af411a5ada3ffabb-5704191-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=2a0000017a11dbf5e3fd69ff1dde1c3c63eb-3483535-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=0298b1ea3a28c755f59b7d6e5936da2b-4497405-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=4401bc5a70e7dec78b5a4a6ae769cf02-5378989-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=b52a0aa0cc333f36604e010f10f40f3c-5492023-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=e46974078608d31f23b54fe7d2e58d72-5482565-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=8abef755ded08f3923b3c47cf0eaecdd-5676887-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=2a00000179f4800ec4e83b60e09cfa601917-4012435-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=2a0000017a192743e3f6321b89a3e4768023-4411542-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=d7b32abc04c567097b1293b6a13cd02e-5870008-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=5e97b4282335b667f610fd5005645420-4479838-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=ea356800cdb18bae46ae4bbf5679c4e6-4268599-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=ac46b8014aa4b54a628328634f476264-5870172-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=20620421fc8dd11e9b6a05c311988438-5338505-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=9eaef4a3712fb3900a704e9de4a4b9b7-5544858-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=2a0000017a0f75bd9882de4909faaa7df5a1-4865680-images-thumbs&n=13
https://avatars.mds.yandex.net/i?id=30ae049201b80c5aaf6756ca7fbc91bc-4369943-images-thumbs&n=13

Process finished with exit code 0
contikiv1
да, спасибо, этот код я уже написал
вот если бы параметры типа img_href извлечь (это линк на картинку в источнике)
если выполнить код, то можно их найти в выводимом коде
 rs = requests.get(url, proxies=proxies, verify = path_sert).content
rs_bs = BeautifulSoup(rs, 'html.parser')
print(rs_bs)

но БС их не извлекает)
xam1816
 import requests
from bs4 import BeautifulSoup
import re
import json
headers = {
    'sec-fetch-site': 'same-origin',
    'upgrade-insecure-requests': '1',
    'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.174 YaBrowser/22.1.2.834 Yowser/2.5 Safari/537.36',
}
url = 'https://yandex.ru/images/search?from=tabbar&text=%D0%B3%D0%B0%D0%B7%D0%BE%D0%B0%D0%BD%D0%B0%D0%BB%D0%B8%D0%B7%D0%B0%D1%82%D0%BE%D1%80%20%D0%B0%D0%B2%D0%B3-4-0.01'
rs = requests.get(url, headers=headers).content
soup = BeautifulSoup(rs, 'lxml')
res = soup.find_all(attrs={'data-bem':re.compile('img_href')})
for i in res:
    s = i['data-bem']
    d = json.loads(s)
    print(d['serp-item']['img_href'])

https://zapadpribor.com/static/images/catalog/15799/800x600/ltk-13u-sp-11-photo-7.jpg
https://studfile.net/html/2706/176/html_cXiI16ildp.U79v/img-kcxM8T.jpg
https://28.img.vipimg.ru/uploads/sdwt5jku12saa/1450623537_Gazoanalizator-avg-4-klass-1.jpg
https://img.bizorg.su/goods/532/948/5329487.jpeg
https://elementradio.ru/wp-content/uploads/avg-4-2-01.jpg
https://a.d-cd.net/mcAAAgM6wOA-1920.jpg
https://39.img.avito.st/288x216/4550029039.jpg
https://28.img.vipimg.ru/uploads/sdwt5jku12saa/1450623537_Gazoanalizator-avg-4-klass-1_2.jpg
http://promsouz.com/image/cache/catalog/product_store/955-500x500.jpg
https://28.img.vipimg.ru/uploads/sdwt5jku12saa/1450623537_Gazoanalizator-avg-4-klass-1_3.jpg
https://all-pribors.ru/pics/original/27861-14-0000.jpg
http://www.vrn-garo.ru/upload/iblock/300/3008ed782ec87533742d45d1efa52630.jpg
https://vsedlyasto.ru/upload/ammina.optimizer/jpg/q80/upload/iblock/4a8/2c9f35af1ec4c973be8d27732a086914.jpg
https://images.ru.prom.st/802552528_w640_h640_gazoanalizator-avtotest-0102p-2.jpg
https://carmasters.org/downloads/monthly_2018_01/udhLCB8Th1k.jpg.921da1bba9d6ca8c7ab4fe8015e3bfec.jpg
https://analytprom.ru/wp-content/uploads/2015/08/%D0%93%D0%98%D0%90%D0%9C-29%D0%9C-%D1%86%D0%B5%D0%BD%D0%B0.jpg
http://elegas.com/images/Binar1p.jpg
https://images.ru.prom.st/531857602_w640_h640_mnogokomponentnyj-gazoanalizator-avtotest.jpg
https://pa-irk.ru/image/catalog/gazoanalizator/8/168571015-gazoanalizator-avtotest-01-03p.jpg
https://www.graduz.ru/seitron/images/stories/full_a1e4841a20dc679f847c83d3e990b5201.jpg
https://www.teh-avto.ru/userfiles/proditem/img291.jpg
https://eksacom.ru/MyWeb-Image/table/files/field/file/content-field/content/equality-field/id/equality/928/1/avtotest0103mb.jpg
https://analytprom.ru/wp-content/uploads/2020/08/%D0%90%D0%92%D0%A2%D0%9E%D0%A2%D0%95%D0%A1%D0%A2-01.04-2-%D0%BA%D0%BB.jpg
https://gazoanalit.ru/upload/iblock/ac5/sigma-03_1.JPG.jpg
https://semilab.ru/image/cache/catalog/rassev/vesu/sushilnye-shkafy-serii-dso/perch/h2s-725--1200x800.jpg
https://spb.ank-ndt.ru/storage/products/xhlhkcy5GafaerDcCsRJYi04s.jpg
http://spb.alloy.ru/media/images/2012/02/28/big/cc9256aa4a12747a1ac74ddbb40e3e7f.jpeg
https://pribori24.ru/wp-content/uploads/2020/12/44479-img-1.jpg
https://kvazar-ufa.com/images/thumbnails/800/700/detailed/12/%D0%93%D0%90%D0%97%D0%9E%D0%90%D0%9D%D0%90%D0%9B%D0%98%D0%97%D0%90%D0%A2%D0%9E%D0%A0_%D0%90%D0%9D%D0%A2-3,%D0%90%D0%9D%D0%A2-3%D0%9C___3.jpg
https://images.ru.prom.st/395166705_w640_h640_gazoanalizator-pga-600.jpg

Process finished with exit code 0
contikiv1
Большое спасибо!

применял БС, но для случаев когда явно классы, теги были

как правильно сформулировать запрос в гугл чтобы эти строки понять?
soup = BeautifulSoup(rs, ‘lxml’)
res = soup.find_all(attrs={'data-bem':re.compile('img_href')})
xam1816
Beautifulsoup documentation ссылка.
вот на русском ссылка
contikiv1
спасибо!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB