Home > other >  (for help, want to climb in the world of time, here is the source code, thank you)
(for help, want to climb in the world of time, here is the source code, thank you)

Time:11-21

The import json
The import requests
The from requests. Exceptions import RequestException
The import re
The import time def get_one_page (url) : try: headers={' the user-agent ':' Mozilla/5.0 (Windows NT 6.1; Win64. X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36 '} response=requests. Get (' http://www.24timemap.com/'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; Div. *?> (. *?)
. *? (a/d +). *?
') the items=re. The.findall (pattern, HTML) for the item in the items: yield {' location: item [0], 'time: the item [1]} print (item) write_to_file (item)
Def write_to_file (content) : with the open (' r1. TXT ', 'a', encoding="utf-8") as f: f.w rite (json. Dumps (content, ensure_ascii=False) + '\ n') time. Sleep (1)

CodePudding user response:

The pattern=re.com running (' & lt; Div. *?> (. *?)
. *? (a/d +). *?
')
This is what you want to match???
To tell you the truth, this thing any div tags have digital eligible
What you want to, can you capture

CodePudding user response:

references on 1st floor day I reply:
pattern=re.com running (' & lt; Div. *?> (. *?)
. *? (a/d +). *? ')
This is what you want to match???
To tell you the truth, this thing any div tags have digital eligible
You to something, can you screenshots to see
hello, I want to get this site is a time in various areas of the world's web site, I'm going to get place and time, I thought that is also my regular expression was wrong and then I went to the novice tools of regular expressions test my regular expression, there is access to the site, I need have time, but running the code can not run normally, also does not have an error,

CodePudding user response:

You use canonical parse this (' & lt; Div. *?> (. *?) . *? (a/d +). *? '), with xpath parsing is not better,
Can you send the url

CodePudding user response:

This code is written according to my understanding, some third-party libraries you may not have, you need to download the
The import requests
The from fake_useragent import UserAgent
The from LXML import etree

If __name__=="__main__ ':
Url_='http://www.24timemap.com/'
Headers_={
'the user-agent: UserAgent (). The random
}
Response_=requests. Get (url_, headers=headers_). The text
Html_response=etree. HTML (response_)
Area_=html_response. Xpath ('//div/@//li//a [@ target="_blank"]/text () ')
Time_=html_response. Xpath ('//div/@//li//I/text () ')
Area_time={}
For I in range (len (area_) :
=time_ area_time [area_ [I]] [I]
Print (area_time)
This is my run results

Page link:https//www.codepudding.com/other/85132.html

  • Related