【发布时间】:2025-12-13 05:45:01
【问题描述】:
我有以下问题:我尝试抓取名称普查网站 (https://namecensus.com/male_names.htm) 使用以下代码:
for counter in range(0, len(links_male)):
print("Sleeping for 2 Seconds")
time.sleep(2)
print(url)
html_page=rq.get(url)
bs_instance_male=BeautifulSoup(html_page.text,"html.parser")
print(bs_instance.h1)
table_entries=bs_instance.select(".datatable > table >tr >td")
for entry in table_entries:
male_firstname_data.append(entry)
#Update Url
counter+=1
if(counter<len(links_male)):
url=links_male[counter]
print(f"URL updating to: {url}")
else:
print("Done")
这给出以下输出:picture of output
正如您所见,尽管 URL-String 已正确更新,但它不会以某种方式更新变量 html_page? 有人可以解释一下为什么会这样吗? 谢谢!!
【问题讨论】:
-
您应该在代码围栏中添加输出(``` ```),而不是在屏幕截图中。
标签: python get python-requests screen-scraping