输出无法正确..想要提取所有页面,但获得前2页的输出

时间:2019-01-07 09:32:33

标签: python beautifulsoup

from bs4 import BeautifulSoup
import requests
for count in range(1,805):
   headers = {'User-Agent':'Googleboat'}
   r = requests.get("https://www.medindia.net/patients/doctor_search/dr_result.asp?alpha=&page= "+str(count)+ "&dr_name=&city=&state=Maharashtra&pincode=&Specialist=",headers=headers) 
   soup = BeautifulSoup(r.text,'lxml')

   links = soup.find('div',class_='dr-lists ')
   for link in soup.find_all('div',class_='col-xs-12 col-sm-12 col-md-12'):
      for l in link.find_all('a'):
        c = (l.get('href'))
        link = "https://www.medindia.net/patients/doctor_search/" + c
        r = requests.get(link)
        soup = BeautifulSoup(r.text,'lxml')

        try:
           data = soup.find('div',class_='col-xs-12')
           h3 = data.find('h3')
           print (h3.text)
        except:
           pass
        try:
           p = data.findAll('p')

           for pdata in p :
               print (pdata.text)

        except:
           pass

0 个答案:

没有答案