Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mysql.connector
- import os
- import threading
- from bs4 import BeautifulSoup
- import re
- from urllib.request import urlopen
- from mysql.connector import errorcode
- song=0
- page=0
- def get_links(url,superpage):
- global song
- global page
- superlength=len(superpage)
- try:
- ip=urlopen(url)
- inp=BeautifulSoup(ip,"html.parser")
- ip.close()
- except:
- print("link not working moveving to next link")
- ip=""
- inp=BeautifulSoup(ip,"html.parser")
- l = inp.find_all('a',href=True)
- for links in l:
- main=links['href']
- if len(main)>=2:
- #remove hashtag pages
- if main[0]=="#":
- main="hashtag"
- elif main[0]==".":
- main=main[1:]
- #detect http links
- elif main[:7]=="http://" or main[:8]=="https://":
- main=main
- #add http to // links
- elif main[:2]=="//":
- main="http:"+main
- #add paraent to / link
- elif main[0]=="/":
- main=url+main
- #add superpage to other links
- else:
- main=superpage+"/"+main
- #replace space with %20
- main=main.replace(" ","%20")
- if main[-3:]=="mp3":
- song=song+1
- pos=main.rfind("/")
- name=main[pos+1:]
- name=name.replace("%20"," ");
- sql = "INSERT INTO music (name,link,parent,super)VALUES ('"+name+"','"+main+"','"+url+"','"+superpage+"')"
- #create connection
- try:
- conn=mysql.connector.connect(
- user='root',
- password='root',
- host='localhost',
- database='musicSearch',
- port='8889'
- )
- except mysql.connector.Error as e:
- print(e)
- cur=conn.cursor(buffered=True)
- cur.execute(sql)
- cur.close()
- conn.close()
- #working with otherlinks
- else:
- #check if page is done
- #create connection
- try:
- conn=mysql.connector.connect(
- user='root',
- password='root',
- host='localhost',
- database='musicSearch',
- port='8889'
- )
- except mysql.connector.Error as e:
- print(e)
- cur=conn.cursor(buffered=True)
- qq = "SELECT page from done where page='"+main+"'"
- cur.execute(qq)
- n=cur.rowcount
- cur.close()
- conn.close()
- if n<=0:
- try:
- conn=mysql.connector.connect(
- user='root',
- password='root',
- host='localhost',
- database='musicSearch',
- port='8889'
- )
- except mysql.connector.Error as e:
- print(e)
- cur=conn.cursor(buffered=True)
- x = "INSERT INTO done (page) VALUES ('"+main+"')"
- cur.execute(x)
- conn.commit()
- cur.close()
- conn.close()
- page=page+1;
- t=threading.Thread(target=get_links,args=(main,superpage))
- t.start()
- _=os.system("clear")
- print(threading.activeCount())
- print("songs:{}".format(song))
- print("Pages Done:{}".format(page))
- get_links("http://songspk3.co/","http://songspk3.co/")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement