【发布时间】:2022-01-14 12:53:18
【问题描述】:
我正在尝试运行这个属于房地产数据 WebScraping 项目 (https://github.com/arturlunardi/webscraping_vivareal/blob/main/scrap_vivareal.ipynb) 一部分的块代码,但我在卡循环中遇到错误并且想不出解决方案(我是抓取的初学者部分)
# Web-Scraping
for line in soup.findAll(class_="js-card-selector"):
try:
full_address=line.find(class_="property-card__address").text.strip()
address.append(full_address.replace('\n', '')) #Get all address
if full_address[:3]=='Rua' or full_address[:7]=='Avenida' or full_address[:8]=='Travessa' or full_address[:7]=='Alameda':
neighbor_first=full_address.strip().find('-')
neighbor_second=full_address.strip().find(',', neighbor_first)
if neighbor_second!=-1:
neighbor_text=full_address.strip()[neighbor_first+2:neighbor_second]
neighbor.append(neighbor_text)
else: # Bairro não encontrado
neighbor_text='-'
neighbor.append(neighbor_text)
else:
get_comma=full_address.find(',')
if get_comma!=-1:
neighbor_text=full_address[:get_comma]
neighbor.append(neighbor_text)
else:
get_hif=full_address.find('-')
neighbor_text=full_address[:get_hif]
neighbor.append(neighbor_text)
File "/tmp/ipykernel_70908/2775873616.py", line 26
^
SyntaxError: unexpected EOF while parsing
有人知道会发生什么吗?
【问题讨论】:
-
问题是代码不完整。其余的代码在哪里?我看到
try:声明。应该有一个与try:一致的except:语句 -
EOF 代表文件结束。正如我所说,代码是不完整的。错误说是:
unexpected end-of-file while parsing
标签: beautifulsoup webdriver screen-scraping