From ba8467a2faffb9f3873d54e532f32a77eafd731e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 22 Jul 2019 21:55:19 +0200 Subject: [PATCH] Scraping --- README.md | 12 ++++++++++-- index.html | 10 ++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f60ecff..0daaf9b 100644 --- a/README.md +++ b/README.md @@ -2292,8 +2292,8 @@ Scraping import requests from bs4 import BeautifulSoup url = 'https://en.wikipedia.org/wiki/Python_(programming_language)' -page = requests.get(url) -doc = BeautifulSoup(page.text, 'html.parser') +resp = requests.get(url) +doc = BeautifulSoup(resp.text, 'html.parser') table = doc.find('table', class_='infobox vevent') rows = table.find_all('tr') link = rows[11].find('a')['href'] @@ -2301,6 +2301,14 @@ ver = rows[6].find('div').text.split()[0] print(link, ver) ``` +#### Downloads Python's logo: +```python +url_img = rows[0].find('img')['src'] +image = requests.get(f'https:{url_img}').content +with open('test.png', 'wb') as file: + file.write(image) +``` + Web --- diff --git a/index.html b/index.html index dce5113..caea88c 100644 --- a/index.html +++ b/index.html @@ -1973,8 +1973,8 @@ logger.<level>('A logging message.') import requests from bs4 import BeautifulSoup url = 'https://en.wikipedia.org/wiki/Python_(programming_language)' -page = requests.get(url) -doc = BeautifulSoup(page.text, 'html.parser') +resp = requests.get(url) +doc = BeautifulSoup(resp.text, 'html.parser') table = doc.find('table', class_='infobox vevent') rows = table.find_all('tr') link = rows[11].find('a')['href'] @@ -1983,6 +1983,12 @@ print(link, ver) +
url_img = rows[0].find('img')['src']
+image   = requests.get(f'https:{url_img}').content
+with open('test.png', 'wb') as file:
+    file.write(image)
+
+

#Web

# $ pip3 install bottle
 from bottle import run, route, post, template, request, response
 import json