我是 IT 专业的菜鸟学生,我试图帮助我的朋友完成工作,我想创建一个他可以服务的客户列表(也许将其导出到文件中也很棒,但我稍后会考虑)猜测)。
当我尝试运行代码时,它只返回一个空列表,您有什么建议吗?
任何建议/反馈将不胜感激!
谢谢你!(我知道也许这不是您见过的最好的代码!所以我提前向自己道歉!)
import requests
from bs4 import BeautifulSoup
import pprint
res = requests.get('https://www.paginebianche.it/toscana/li/gommisti.html')
res2 = requests.get('https://www.paginebianche.it/ricerca?qs=gommisti&dv=li&p=2')
soup = BeautifulSoup(res.text, 'html.parser')
soup2 = BeautifulSoup(res2.text, 'html.parser')
links = soup.select('.org fn')
subtext = soup.select('.address')
links2 = soup2.select('.org fn')
subtext2 = soup2.select('.address')
mega_links = links + links2
mega_subtext = subtext + subtext2
def create_custom_hn(mega_links,mega_subtext):
hn = []
for links,address in enumerate(mega_links):
title = links.getText()
address= address.getText()
hn.append({'title': title, 'address': address})
return hn
pprint.pprint(create_custom_hn(mega_links,mega_subtext))
忽然笑
相关分类