编程语言
首页 > 编程语言> > python爬取企业登记业务

python爬取企业登记业务

作者:互联网


如果你对python感兴趣,我这有个学习Python基地,里面有很多学习资料,感兴趣的+Q群:688244617

1 import requests
 2 from lxml import etree
 3 import csv
 4 
 5 for i in range(10, 990, 10):
 6 
 7     url = "http://124.128.84.60:7008/iaicweb/xxcx/doqylccx.jsp?start=%s" % (str(i))
 8 
 9     response = requests.get(url)
10     html = etree.HTML(response.text)
11 
12     content_list = html.xpath('//td[@align="center"]/table[@border="1"]//tr[not(@class="tc")]')
13 
14     for content in content_list[:-2]:
15         try:
16             banlishixiang = content.xpath('./td[not(@colspan="4")]/text()')[0]
17             shendingdanwei = content.xpath('./td[not(@colspan="4")]/text()')[1]
18             banliriqi = content.xpath('./td[not(@colspan="4")]/text()')[2]
19             banlizhuangtai = content.xpath('./td[not(@colspan="4")]/text()')[3]
20         
21             with open('./登记业务.csv', 'a', encoding='utf-8') as f:
22                 csv_write = csv.writer(f)
23                 rows = [banlishixiang, shendingdanwei, banliriqi, banlizhuangtai]
24                 csv_write.writerow(rows)
25 
26         except:
27             continue

标签:xpath,content,登记,python,text,爬取,colspan,td,csv
来源: https://blog.csdn.net/weixin_45342712/article/details/99676118