Home > other >  For help, regular expressions are correct, but the program does not run
For help, regular expressions are correct, but the program does not run

Time:09-26

The import requests
The import json
The import re
The import time
The from requests. Exceptions import RequestException
Url='http://www.24timemap.com/'
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 '} response=requests. Get (url, headers=headers). If the response status_code==200: return response. The text return None except RequestException: return None
Def parse_one_page (HTML) : the pattern=re.com running (' & lt; Li. *? Bg. *? The title. *?> (. *?) 're. S) 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')

CodePudding user response:

Haven't see pages, but it is recommended that you use the code inserts, this watch is too messy

CodePudding user response:

Suggest you resend code inserted
  • Related