2016-02-25 64 views
0

我希望用户给出搜索类型选项,搜索文本,然后显示所得到的网页中的所有链接。但我不能够检索得到的链接(只家乡链路检索)从网页(http://djraag.net/bollywood/searchbycat.php所有未从网页检索的链接 - python

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']) 

回答

1

卸下代码行

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

,然后再试一次。

+0

谢谢,它的工作 –