我需要得到今天和前一天发布的信息。另外,当导入到csv文件时,它只打印第一列而不是剩余的列。你知道吗
网址:https://e-mehkeme.gov.az/Public/Cases
以<td style="width:95px;text-align:center">28.10.2019</td>
形式存储在html中的日期
import requests, re
from bs4 import BeautifulSoup as bs
import csv
request_headers = {
'authority': 'e-mehkeme.gov.az',
'method': 'POST',
'path': '/Public/Cases',
'scheme': 'https',
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,'
'application/signed-exchange;v=b3',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en,en-GB;q=0.9',
'cache-control': 'max-age=0',
'content-length': '66',
'content-type': 'application/x-www-form-urlencoded',
'origin': 'https://e-mehkeme.gov.az',
'referer': 'https://e-mehkeme.gov.az/Public/Cases',
'upgrade-insecure-requests': '1',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/75.0.3770.142 Safari/537.36',
}
voens = {'3100608381',
}
form_data = {
'CourtId': '',
'CaseNo': '',
'DocFin': '',
'DocSeries': '',
'DocNumber': '',
'VOEN': voens,
'button': 'Search',
}
url = 'https://e-mehkeme.gov.az/Public/Cases?courtid='
response = requests.post(url, data=form_data, headers=request_headers)
s = bs(response.content, 'lxml')
# PRINT THE CONTENTS OF EACH SEARCH!
for voen in voens:
form_data['VOEN'] = voen
r = requests.post('https://e-mehkeme.gov.az/Public/Cases', data=form_data)
soup = bs(r.text, 'lxml')
ids = [i['value'] for i in soup.select('.casedetail')]
for i in ids:
r = requests.get(f'https://e-mehkeme.gov.az/Public/CaseDetail?caseId={i}')
soup = bs(r.content, 'lxml')
output = [re.sub('\s+', ' ', i.text.strip()) for i in soup.select('[colspan="4"]')]
print(output)
with open('courtSearch.csv', 'w', newline='', encoding='utf-8') as myfile:
writer = csv.writer(myfile, quoting=csv.QUOTE_ALL)
writer.writerow(output)
期望输出:
下面使用了一个稍微不同的url构造,这样您就可以使用GET请求并轻松地收集每个
voen
的所有结果页面。我在每个请求期间收集字符串日期和caseid(对于以后的请求是必需的)。然后,我使用一个掩码(对于感兴趣的日子,例如今天和昨天,转换为与网站上相同格式的字符串)只过滤所需日期范围内的id。然后我循环过滤列表并发出弹出窗口信息请求。你知道吗在代码中还可以看到注释掉的部分。其中一个向您显示从每个页面检索到的结果
我正在拆分标题短语(因此假设这些短语是常规的),以便可以将行中的每个字符串拆分为相应的输出列。你知道吗
可能需要bs4 4.7.1+
我在多个分隔符上搜索拆分,并使用@Jonathanhere给出的思想。所以投票支持该用户的信用。你知道吗
相关问题 更多 >
编程相关推荐