import requests
import json
from bs4 import BeautifulSoup
url = 'https://www.tiktok.com/@golden_men_6/video/6803237854542712070'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'}
r = requests.get(url, headers=headers)
soup = BeautifulSoup(r.content, 'html.parser')
script = soup.find('script', attrs={'id': 'videoObject'})
data = json.loads(script.next)
video_url = data['contentUrl']
print(video_url)
from lxml import html
lxml_string = '''<div class="reader-view" data-p="2">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/274px-PNG_transparency_demonstration_1.png">
</div>'''
tree = html.document_fromstring(lxml_string)
pic_path = tree.xpath('//img/@src')[0]
import requests
r = requests.get(pic_path, allow_redirects=True)
open('d:\\02.png', 'wb').write(r.content)
import requests
proxies = {"https": "socks4://212.200.118.98:1080"}
...
resp = requests.post(tg_url, files=files, data=data, proxies=proxies)
import requests
proxies = {"https": "socks4://212.200.118.98:1080"} #Сербская прокся, отправляет через раз
tg_token = 'xxxxxxxxxxx'
tg_url = "https://api.telegram.org/bot" + tg_token + "/sendPhoto"
tg_chat_id = "@groupity1"
caption = 'yyyyyy yyyy yyyy'
files = {'photo': open('d://photo1.png', 'rb')}
data = {'chat_id' : tg_chat_id, 'caption': caption}
resp = requests.post(tg_url, files=files, data=data, proxies=proxies)
print(resp)
import requests
raw = requests.get("https://de1.api.radio-browser.info/json/stations/bycountryexact/Ukraine")
print(raw.content)
import json
jsoned = json.loads(raw.content)
print(jsoned[0])
#requests - для скачки странички
import requests
#html из lxml - чтобы парсить DOM дерево
from lxml import html
#забираем страничку с нефтью
raw = requests.get("https://yandex.ru/news/quotes/1006.html")
#строим из нее html дерево
dom = html.fromstring(raw.content)
#забираем xpath-ом ноды с датами и ценами из дерева
dates = dom.xpath('//td[@class="quote__date"]')
prices = dom.xpath('//td[@class="quote__value"]')
#выводим на экран
for d,p in zip(dates, prices):
print(d.text_content(), p.text_content())