【问题标题】:Trying to scrape from mutiple pages with same link尝试从具有相同链接的多个页面中抓取
【发布时间】:2019-10-05 18:11:30
【问题描述】:
from bs4 import BeautifulSoup
import requests
import time
from selenium import webdriver

driver = webdriver.Chrome(r'C:\chromedriver.exe')
url ='https://www.sambav.com/hyderabad/doctors'

driver.get(url)

soup = BeautifulSoup(driver.page_source,'html.parser')

for links in soup.find_all('div',class_='sambavdoctorname'):
    link = links.find('a')
    print(link['href'])

driver.close()

我正在尝试抓取此页面,所有页面中的链接都相同。我正在尝试从所有多个页面中提取链接,但它没有提供任何输出,也没有显示任何错误,只是程序结束了。

【问题讨论】:

    标签: python selenium


    【解决方案1】:

    如果您通过浏览器(chrome 或 mozilla 等)中的开发人员工具检查该网站,则在加载网站之前,该网站会从少数来源获取数据。其中一个来源是 "https://www.sambav.com/api/search/DoctorSearch?searchText=&city=Hyderabad&location=" 。您的代码可以简化(并且不需要使用 selenium):

    import requests
    r = requests.get('https://www.sambav.com/api/search/DoctorSearch?searchText=&city=Hyderabad&location=') 
    BASE_URL_DOCTOR = 'https://www.sambav.com/hyderabad/doctor/'
    for item in r.json():
        print(BASE_URL_DOCTOR + item['uniqueName'])
    

    【讨论】:

      猜你喜欢
      • 2020-04-27
      • 2020-09-21
      • 2022-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-10
      • 1970-01-01
      相关资源
      最近更新 更多