Added code to replace <br/> by \n in positions
This commit is contained in:
parent
1337d3ce8a
commit
b3788fe34d
9
fetch.py
9
fetch.py
@ -7,12 +7,14 @@ Created on Mon Nov 5 20:55:36 2018
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
def runfetch(url):
|
def runfetch(url):
|
||||||
session=requests.Session()
|
session=requests.Session()
|
||||||
req1=session.get(url)
|
req1=session.get(url) # Get the source code
|
||||||
text=req1.text.split('\n')
|
text=req1.text.split('\n')
|
||||||
|
# Parse the HTML source code
|
||||||
text=['\n'.join(row.split('\n')[:row.split('\n').index("</tr>"):]) for row in '\n'.join(text[text.index('<br/>ANNEXES<br/>ANNEXE I</p>'):text.index('<div style="margin-top: 30px; margin-bottom:20px;" id="JORFSCTA000037493059" class="titreSection">Annexe </div>'):]).split('<tr>')[2::]]
|
text=['\n'.join(row.split('\n')[:row.split('\n').index("</tr>"):]) for row in '\n'.join(text[text.index('<br/>ANNEXES<br/>ANNEXE I</p>'):text.index('<div style="margin-top: 30px; margin-bottom:20px;" id="JORFSCTA000037493059" class="titreSection">Annexe </div>'):]).split('<tr>')[2::]]
|
||||||
diclist=[]
|
diclist=[]
|
||||||
for row in text:
|
for row in text:
|
||||||
@ -23,8 +25,11 @@ def runfetch(url):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
diclist=runfetch('https://www.legifrance.gouv.fr/eli/arrete/2018/10/12/PRMD1824595A/jo/texte')
|
diclist=runfetch('https://www.legifrance.gouv.fr/eli/arrete/2018/10/12/PRMD1824595A/jo/texte') # Fetch all the data from a french article
|
||||||
url='https://www.legifrance.gouv.fr/eli/arrete/2018/10/12/PRMD1824595A/jo/texte'
|
url='https://www.legifrance.gouv.fr/eli/arrete/2018/10/12/PRMD1824595A/jo/texte'
|
||||||
|
for index, zone in enumerate(diclist):
|
||||||
|
for element in zone:
|
||||||
|
diclist[index][element] = re.sub("<br.{0,2}>", "\n", diclist[index][element]) # Replace <br>, <br /> and <br/> by \n
|
||||||
# Print the dict
|
# Print the dict
|
||||||
print("===== Dict =====")
|
print("===== Dict =====")
|
||||||
for index, zone in enumerate(diclist):
|
for index, zone in enumerate(diclist):
|
||||||
|
Loading…
Reference in New Issue
Block a user