Home > other >  Help!!!!! Why the code or can not run normally
Help!!!!! Why the code or can not run normally

Time:09-26

 import requests 
The import json
The import re
The from requests. Exceptions import RequestException
The import time


Def get_one_page (url) :
Try:
Headers={
'the user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10 _13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36 '
}
The response=requests. Get (url, headers=headers)
If the response. Status_code==200:
Return the response. The text
Return None
Except RequestException:
Return None


Def parse_one_page (HTML) :
The pattern=re.com running (' & lt; Li. *? Bg. *? The title. *?> (. *?) (. *?) ')
The items=re. The.findall (pattern, HTML)
For the item in the items:
Yield {
'locantion: item [0],
'time: the item [1]
}


Def write_to_file (content) :
With the open, 'says Mr Galdi at SLW. TXT', 'a', encoding="utf-8") as f:
F.w rite (json. Dumps (content, ensure_ascii=False) + '\ n')

Url='http://www.24timemap.com/'
PageHtml=get_one_page (url)
RespGenerator=parse_one_page (pageHtml)
For eachItemDict respGenerator in:
Write_to_file (eachItemDict)
Time. Sleep (1)

CodePudding user response:

You will not be able to seriously study the python code indentation requirement?

CodePudding user response:

reference 1/f, old coconut response:
you will not be able to seriously study the python code indentation requirement?
thank you for your advice!!!!!!!!!! I am serious to see!! I were done by the crawler

CodePudding user response:

  • Related