Python makes the most beautiful crawler for applications

Source: Internet
Author: User
Android is the most beautiful application page crawler, crawler is very simple, the design of things to quite a lot of
File operations
Regular expressions
String substitution and so on

Import Requestsimport Reurl = "http://zuimeia.com" R = Requests.get (' http://zuimeia.com/community/app/hot/?platform= 2 ') pattern = Re.compile (r ') urllist = Pattern.findall (r.content) def requestsurl (URL): r = Requests.get (URL) title = re.fi Ndall (R ' "App-title" >

(.*?)

', r.content) #print title category = Re.findall (R ' (. *?) ', r.content) #print category describe = Re.findall (R ' (. *?) ', r.content) #print type (describe[0]) Strdescribe = Srtreplace (describe[0]) #print strdescribe downloadurl = Re.findall (R ' ', '
', '

', '

', '

', '

', '

', '

', '

',' ','

', '
', '

', '', '', '', '', '', '','','', '' for eachlistreplace in listreplace:string = String.Replace (str (eachlistreplace), ' \ n ') string = String.Replace (' \ n ') , ') return stringdef categornfinal (category): Categoryfinal = ' for eachcategory in category:categoryfinal = Categoryfi Nal+str (eachcategory) + '--' return categoryfinaldef urlreplace (URL): url = url.replace (' & ', ' & ') return Urlrequestsurl ("http://zuimeia.com/community/app/27369/?platform=2") for eachurl in Urllist:eachurl = Url+eachurl Content = Requestsurl (eachurl) categoryfinal = ' title = content[0][0] Category = Categornfinal (content[1]) Strdescribe = CONTENT[2] DownloadURL = Urlreplace (content[3][0]) with open (' C:/wqa.txt ', ' A + ') as Fd:fd.write (' title: ' +title+ ' \ n ' + ') Category: ' +category+ ' \ n ' + ' Strdescribe: ' +strdescribe+ ' \ n ' + ' DownloadURL: ' +downloadurl+ ' \n\n\ N------------------------------------------------------------------------------------------------------------------------ -----\n\n\n ')
  • 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: info-contact@alibabacloud.com 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.