import requests, sys, bs4, pyperclip, webbrowser, os from math import log ''' Processing the string searchTerm ''' if len(sys.argv)>1: searchTerm=' '.join(sys.argv[1:]) else: searchTerm=pyperclip.paste() ''' Downloading the search page, finding all the elements that contain dt a, which on mangahere.co contain the results ''' res=requests.get('http://mangahere.co/search.php?name='+ searchTerm) res.raise_for_status() soup=bs4.BeautifulSoup(res.text,"html.parser") results=soup.select('dt a') ''' Printing all the names from the results and storing the links of each name to "links" ''' links=[] names=[] for i in range(int(len(results)/2)): names.append(str(results[i*2].getText())) links.append(results[i*2].get('href')) for i in range(len(names)): print(i+1," "*(1-int(log(i+1,10))),"| ",names[i]) print(" |") print() ''' Requiring users to choose manga number(s) and opening tabs for the manga chosen ''' action=input("Do you want to: (1) Go to the site(s) or (2) Download the manga? ") if int(action)==1: if len(links)==1: webbrowser.open(links[0]) else: answer=input("Choose manga number(s): ") nums=answer.split(' ') for i in range(len(nums)): webbrowser.open(links[int(nums[i])-1]) else: if len(links)==1: target=1 else: answer=input("Choose manga number to download: ") target=int(answer) os.chdir("Manga") os.makedirs(names[target-1],exist_ok=True) print(names[target-1]) res=requests.get(links[target-1]) res.raise_for_status() soup=bs4.BeautifulSoup(res.text,"html.parser") results=soup.select(".main span a") links=[] for i in range(len(results)): links.append(results[i].get("href")) print("Found",len(links),"chapters. Started downloading...") res=requests.get(links[-1]) res.raise_for_status() soup=bs4.BeautifulSoup(res.text,"html.parser") comicElement=soup.select(".read_img a img") if comicElement==[]: print("Could not find image") else: try: comicUrl=comicElement[1].get('src') subRes=requests.get(comicUrl) subRes.raise_for_status() except requests.exceptions.MissingSchema:
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question