|
发表于 2022-7-20 07:54:19
|
显示全部楼层
本楼为最佳答案
- import requests
- from lxml import etree
- url = "https://beijing.zbj.com/search/service/?l=0&kw=saas&r=1"
- resp = requests.get(url)
- # print(resp.text)
- # 解析
- html = etree.HTML(resp.text)
- p = []
- for i in range(1, 51):
- name = html.xpath(
- '//*[@id="__layout"]/div/div[3]/div/div[3]/div[4]/div[1]/div[{}]/a/div[2]/div[1]/div/text()'.format(
- i
- )
- )[0]
- money = html.xpath(
- '//*[@id="__layout"]/div/div[3]/div/div[3]/div[4]/div[1]/div[{}]/div[3]/div[1]/span/text()'.format(
- i
- )
- )[0]
- location = (
- html.xpath(
- '//*[@id="__layout"]/div/div[3]/div/div[3]/div[4]/div[1]/div[{}]//div[3]/div[1]/div/text()'.format(
- i
- )
- )[0]
- .replace("\n", "")
- .replace(" ", "")
- )
- p.append([name, money, location])
- print(p)
复制代码 |
|