【发布时间】:2020-06-16 11:12:24
【问题描述】:
<td>
<input type="hidden" name="ctl00$ContentPlaceHolder1$dlstCollege$ctl01$hdnInstituteId" id="ContentPlaceHolder1_dlstCollege_hdnInstituteId_1" value="866 " />
<a id="ContentPlaceHolder1_dlstCollege_hlpkInstituteName_1" href="CollegeDetailedInformation.aspx?Inst=866 ">A.N.A INSTITUTE OF PHARMACEUTICAL SCIENCES & RESEARCH,BAREILLY (866)</a>
<br />
<b>Location:</b>
<span id="ContentPlaceHolder1_dlstCollege_lblAddress_1">13.5 km Bareilly - Delhi road, near rubber factory agras road ,Bareilly</span>
<br />
<b>Course:</b>
<span id="ContentPlaceHolder1_dlstCollege_lblCourse_1">B.Pharm,</span>
<br />
<b>Category:</b>
<span id="ContentPlaceHolder1_dlstCollege_lblInstituteType_1">Private</span>
<br />
<b>Web Address:</b>
<a id="lnkBtnWebURL" href='' target="_blank"></a>
<br />
</td>
</tr>
<tr>
<td>
<input type="hidden" name="ctl00$ContentPlaceHolder1$dlstCollege$ctl02$hdnInstituteId" id="ContentPlaceHolder1_dlstCollege_hdnInstituteId_2" value="486 " />
<a id="ContentPlaceHolder1_dlstCollege_hlpkInstituteName_2" href="CollegeDetailedInformation.aspx?Inst=486 ">A.N.A.COLLEGE OF ENGINEERING & MANAGEMENT,BAREILLY (486)</a>
<br />
<b>Location:</b>
<span id="ContentPlaceHolder1_dlstCollege_lblAddress_2">13.5 Km. NH-24, Bareilly-Delhi Highway, Near Rubber Factory, Bareilly</span>
<br />
<b>Course:</b>
<span id="ContentPlaceHolder1_dlstCollege_lblCourse_2">B.Tech,M.Tech,</span>
<br />
<b>Category:</b>
<span id="ContentPlaceHolder1_dlstCollege_lblInstituteType_2">Private</span>
<br />
<b>Web Address:</b>
<a id="lnkBtnWebURL" href='http://www.anacollege.org/index.html' target="_blank">http://www.anacollege.org/index.html</a>
<br />
</td>
</tr>
我想从这个网站提取一个特定的 URL(例如:CollegeDetailedInformation.aspx?Inst=866),但是这段代码有两个我不想要的标签(例如:http://www.anacollege.org/index.html)。
res = requests.get('https://erp.aktu.ac.in/WebPages/KYC/CollegeList.aspx?City=&CType=&Cu=&Br=&Inst=&IType=')
soup = BeautifulSoup(res.content, 'html.parser')
table = soup.find("table", attrs = {'class':'table table-bordered table-responsive'})
pagelink = []
for anchor in table.findAll('a')[1:]:
link = anchor['href']
print(link)
url = 'https://erp.aktu.ac.in/WebPages/KYC/'+ link
pagelink.append(url)
print(pagelinks)
我写了这段代码,但它正在提取所有链接
CollegeDetailedInformation.aspx?Inst=486
http://www.anacollege.org/index.html
CollegeDetailedInformation.aspx?Inst=602
http://www.aashlarbschool.com
CollegeDetailedInformation.aspx?Inst=032
http://www.abes.ac.in
CollegeDetailedInformation.aspx?Inst=290
http://www.abesit.in
CollegeDetailedInformation.aspx?Inst=913
http://www.abesitpharmacy.in
CollegeDetailedInformation.aspx?Inst=643
http://www.vitsald.com
CollegeDetailedInformation.aspx?Inst=1036
http://www.abss.edu.in
我该如何解决这个问题我只想要与 CollegeDetailedInformation.aspx?Inst= 的链接?部分。
【问题讨论】:
标签: python python-3.x web-scraping beautifulsoup python-requests