2016-05-12 10 views
-2
focus_Search = raw_input("Focus Search ") 
    url = "https://www.google.com/search?q=" 
    res = requests.get(url + focus_Search) 
    print("You Just Searched") 
    res_String = res.text 
    #Now I must get ALL the sections of code that start with "<a href" and end with "/a>" 

Ich versuche, alle Links von einer Google-Suche-Webseite zu kratzen. Ich könnte jeden Link einzeln extrahieren, aber ich bin sicher, dass es einen besseren Weg gibt, es zu tun.Python Link Scraper

+0

einen HTML-Parser verwenden, gibt es unzählige Beispiele auf SO –

Antwort

0

Dies erzeugt eine Liste aller Links in der Suchseite mit einigen Code, ohne in BeautifulSoup zu bekommen

import requests 
import lxml.html 

focus_Search = input("Focus Search ") 
url = "https://www.google.com/search?q=" 
#focus_Search 
res = requests.get(url + focus_Search).content 
# res 

dom = lxml.html.fromstring(res) 
links = [x for x in dom.xpath('//a/@href')] # Borrows from cheekybastard in link below 
# http://stackoverflow.com/questions/1080411/retrieve-links-from-web-page-using-python-and-beautifulsoup 
links