简体   繁体   中英

All Links not retrieved from webpage — python

I would like the user to give search type choices , search text and then display all the links in the resulting webpage . but i am not able to retrieve the resulting links(only home link is retrieved) from the webpage ( http://djraag.net/bollywood/searchbycat.php )

from bs4 import BeautifulSoup
import urllib.request
import re

print(" 1 : Album \n 2 : Track \n 3 : Artist \n ")
count = 0
while (count == 0):
        temp_str = input('Enter yout search type : ')
        temp = int(temp_str)
        if (temp >= 1)&(temp <= 3):
                search_no = temp
                count = 1
        else :
                print("Invalid Input")
if search_no == 1 :
    search_type1 = "album"
     search_type = str(search_type1)
elif search_no == 2:
    search_type1 = "track"
    search_type = str(search_type1)
else:
    search_type1 = "artist"
    search_type = str(search_type1)

Search = input("Search : ")
url_temp = "http://djraag.net/bollywood/searchbycat.php?search="+Search+"&type="+search_type+"&cat_id=5&submit=Submit"

url = urllib.request.urlopen(url_temp)
content = url.read()
soup = BeautifulSoup(content ,"html.parser")

for a in soup.findAll('a',href=True):
        if re.findall('http',a['href']):
                print ("URL:", a['href'])

Remove the line

if re.findall('http',a['href']):

from code and try again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM