Python topic 4: Crawling Movies

Source: Internet
Author: User

Tag:logs   write   request    designation    https     documentation    port    reference    pip   

Import re # Regular expression for extracting data import requests  # download Web page source code ' install requests module: PIP install requests Reference Document: Https://www.cnblogs.com /jamespan23/p/5526311.html ' for m in range (1,5):    url = ' http://www.dytt8.net/html/gndy/dyzz/list_23_ ' +str (m) + ' . html '    html = requests.get (URL) #  use static page    html.encoding = ' GB2312 ' # to specify the encoding format by viewing the Web page source code to know the    data = Re.findall (' <a href= ' (. *?) "class=" Ulink ">", Html.text)    # Extract information, return list    # (. *?) Match any information that begins with ' <a href= ' and ends with ' class= ' Ulink ' ' for    n ' data:        url2 = ' http://www.dytt8.net ' + n        html2 = Requests.get (url2)        html2.encoding = ' GB2312 '        ftp = Re.findall (' <a href= ' (. *?) " >.*?</a></td> ', Html2.text)        try: With            open (R ' F:\python\mov.txt ', ' a ', encoding= ' UTF-8 ') as F:            # Utf-8 is possible compatible, incompatible words using gb2312                f.write (ftp[0]+ ' \ n ') # FTP Extract is a list, the list cannot write to the file, so add [0]        except:            Print (' This page cannot be downloaded ')

  

Python topic 4: Crawling movies

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.