def parse_num(b):
r = requests.get(url=b,headers=headers)
parse_car_num(r.text)
def parse_car_list(a):
tree = etree.HTML(a)
car_list = tree.xpath('//div[@class="bus-layer depth w120"]/div/div/a/@href')
for href_list in car_list:
href_list1 = 'https://xiaogan.8684.cn'+href_list
parse_num(href_list1)
def parse_page():
url = 'https://xiaogan.8684.cn/'
r = requests.get(url,headers=headers)
parse_car_list(r.text)
def main():
parse_page()
fp = open('孝感公交.txt' 'w+', encoding='utf8')
for item in items:
fp.write(str(item))
fp.close()
if __name__ == '__main__':
main()
报错如下:Traceback (most recent call last): File "C:/Users/Administrator/PycharmProjects/untitled5/cxm_test/python/unintest/test_a.py", line 104, in <module> main() File "C:/Users/Administrator/PycharmProjects/untitled5/cxm_test/python/unintest/test_a.py", line 97, in main fp = open('孝感公交.txt' 'w+', encoding='utf8')FileNotFoundError: [Errno 2] No such file or directory: '孝感公交.txtw+'