Python BS4 get href URL

Source: Internet
Author: User
Tags gettext

See the scrape chapter recently. There is a s_urls[0][' href ' that cannot be understood. Think Python has a non-numeric subscript array. After the multi-query to know that this is the tag query in BeautifulSoup


From BS4 import beautifulsoup# what does Thread meansfrom threading import threadimport urllib.request#location of Restaur Antshome_url= "" find_what= "restaurants" location= "London" #Get all restaurants that match the Search Criteria# "https:// "+find_what+" &find_loc= "+locations_html= Urllib.request.urlopen (Search_url). Read () #urlopen (Search_url). Read () print ("Here") Soups_s=beautifulsoup (s_html, "lxml") #Get URLs of top restaurants in ('. Biz-name ' [:]) print (len (s_urls)) print (S_urls) url=[]print (Type (s_urls)) print ( Type (S_urls[0])) print (S_urls[0]) print (s_urls[0][' href ')) for U in Range (len (s_urls)): Url.append (Home_url+s_urls[u] [' href ']) # (URL) #Function that would do actual scraping jobdef Scrape (UR): html=urllib.request.urlopen (UR). read () Soup=beautifulsoup (HTML, "lxml") ('. Biz-page-title ') ('. street-address ') ('. Biz-p ') Hone ') if Title:print ("title:", Title[0].gettext (). Strip ()) if Saddress:print ("Streeet Address:", Sadd Ress[0].gettext (). Strip ()) if Phone:print ("Phone number:", Phone[0].gettext (). Strip ()) print ("--------------- ------") threadlist=[] i=0 #Making thereads to perform scraping while (I<len (URL)): T=thread (target=s Crape,args= (Url[i],)) T.start () threadlist.append (t) i=i+1 for T in Threadlist:t.join ()


Python BS4 get href URL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.