Python Question 4: crawling movies, python question 4

Source: Internet
Author: User

Python Question 4: crawling movies, python question 4

Import re # regular expression, used to extract data import requests # download webpage source code ''' install requests module: pip install requests Reference document: https://www.cnblogs.com/jamespan23/p/5526311.html'''for m in range ): url = 'HTTP: // www.dytt8.net/html/gndy/dyzz/list_23_'{str (m={'.html 'html = requests. get (url) # use static webpage html. encoding = 'gb2312' # specify the encoding format. You can view the source code of the webpage to learn data = re. findall ('<a href = "(. *?) "Class =" ulink "> ', html. text) # extract information and return to the list #(.*?) Match any information starting with '<a href =' and ending with 'class = "ulink" 'for n in 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 may be compatible. If it is not compatible, use gb2312 f. write (ftp [0] + '\ n') # ftp extracts all lists and the list cannot be written to files. Therefore, add [0] writable t: print ('This page cannot be downloaded ')

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.