1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from test_get_data.request import request_get
from test_get_data.url_help import Url
from test_get_data.login import *
 
from bs4 import BeautifulSoup as bs  
import re              #正则表达式
import time
 
import sys
sys.path.append('../../')
import src.core_modules.remove_duplicates_methods as rdm
 
now_date = time.strftime("%Y-%m-%d", time.localtime())    #获取当前年月日  #url编码年月日开始默认时间
now_date1 = time.strftime("%Y-%m", time.localtime())  
month_begin=now_date1+'-01'                 #设置当前月份的开始
 
list_temp=[]  #临时列表  全局变量
 
 
 
#-------------------------------------------------------------------------------------------------------------特殊的url
def get_OnePage_teshu(url,count=1):     #抓取一页的数据,放入list_data中.urls为要访问的网页地址
    global list_temp    #使用全局变量
 
    list_temp.clear()  #清空临时表
 
    r = request_get(url).text
    soup = bs(r,'html.parser')
 
    list=[]                     #创建列表来保存结果
   
    # 找到所有的tr标签
    rows = soup.find_all('tr')
 
    # 提取表格中的数据
    result = []
    for row in rows:
        data = []
        cols = row.find_all('td')
        for col in cols:
            if col.find('div'):
                # 如果td中包含div,则单独提取其内容
                div_content = col.find('div').text.strip()
                # data.append(col.find('td').text.strip())
                # 返回元素的文本内容 搜索tag的直接子节点
                td_content = ''.join(col.find_all(text=True, recursive=False)).strip()
                data.append(td_content)
                data.append(div_content)
            else:
                # 如果td中不包含div,则直接提取td的内容
                td_content = col.text.strip()
                data.append(td_content)
        del (data[-2:])
        del (data[2])
        result.append(data)
     # 删除表头
    del (result[0])
    # 打印提取的数据
    print(result)
 
  
 
    # for tag in tags:  # 每个tag是一行
    #     element = tag.text  # 获取<tr>标签内所有文本信息
    #     element = element.strip()  # 将字符串首尾空格去除
    #     list1 = element.split();  # 以空格为分隔将字符串变为列表
 
    #     # del (list1[-2:])            #列表最后两个元素不需要,删除
    #     # print('删除特殊的后两个')
    #     # print(list1)
    #     list.append(list1) 
    # print(list)
 
    # list_data=[]  
    # for i in list:                   
    #     list_data.append(merge(i))   #将尾日期数据合并成年月日 时分秒
    # del list_data[0]          #删除文字表头   
    # count=count-1             #删除了表头,总数据的行数减一
    # #print(lt_isates_list(list_data)[:]    #将所有数据复制给临时列表list_temp   是去除重复后的列表
    # list_temp=list_data[:]
    # return count
 
if __name__ == '__main__':
    # 登录
    login_fume_web()
    u = Url()
    urls = u.concatenate_url_with_condition('杨记齐齐哈尔烤肉','2023-10-01','2023-10-31',1)
    for item in urls:
        get_OnePage_teshu(item)