-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (43 loc) · 1.78 KB
/
main.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
47
48
49
from bs4 import BeautifulSoup
from googlesearch import search
import os
import requests
import urllib
def Wikipedia():
site = "en.wikipedia.org/"
genre = "Series"
for movie in files:
try:
if os.path.exists(f"{movie}\\"):
for item in os.listdir(f"{movie}\\"):
item = item.split(".")
if ("jpg" in item) or ("png" in item) or ("jpeg" in item):
break
else:
query = site + movie + genre
result = search(query, "com", stop=3) # result of search
for url in result:
if site in url:
r = requests.get(url)
soup = BeautifulSoup(r.text, "html5lib")
selected = soup.find("a", class_="image")
selected = selected.find("img")
img_url = selected.attrs["src"]
img_url = "https:" + img_url
img_format = img_url.split('.')[-1]
urllib.request.urlretrieve(
img_url, f"{movie}\\{movie}.{img_format}") # saving image
print(
f"""---------------------------
name: {movie}\nurl: {url}\nimage url: {img_url}\nstatus:{"✅Ok✅"}
---------------------------""")
break
except AttributeError:
print(
f"""---------------------------
name: {movie}\nurl: {url}\nimage url: {img_url}\nstatus:{"❌Error❌"}
---------------------------""")
continue
if __name__ == "__main__":
files = os.listdir()
Wikipedia()