-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataScraping.py
46 lines (32 loc) · 1.12 KB
/
dataScraping.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from bs4 import BeautifulSoup
import requests
import urllib.request
import shutil
url = 'http://www.jagodibuja.com/webcomic-living-with-hipstergirl-and-gamergirl-english/'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
items = soup.find_all('figure', class_="gallery-item")
# items = soup.find_all('img', class_='attachment-thumbnail')
image_info = []
link_info = []
for i in items:
image_tag = i.findChildren("a")
# print(image_tag)
link_info.append(image_tag[0]['href'])
# print(link_info)
def download_img(img):
response = requests.get(img).content
with open("images/" + str(i) + ".jpg", "wb") as f:
f.write(response)
print('Image scraped successfully.')
for i in range(0, len(link_info)):
# print(link_info[i])
response = requests.get(link_info[i])
soup = BeautifulSoup(response.text, 'html.parser')
items = soup.find_all('img', class_="attachment-large")
for j in items:
download_img(j['src'])
# image_info.append(j['src'])
# print(image_info)
# for i in range(0, len(image_info)):
# download_img(image_info[i])