Sie können alle PDF-Dateien und Reißverschlüsse aus der zweiten Tabelle nach dem id = cPost div, die erhalten:
import requests
from bs4 import BeautifulSoup
r = requests.get("http://www.icai.org/post.html?post_id=10160").text
soup = BeautifulSoup(r, "lxml")
# get second table after cpost
table = soup.select_one("#cpost").select_one("table:nth-of-type(2)")
# find all anchor tags where the href value endswith .pdf and .zip
pdfs = [a["href"] for a in table.select("td a[href$=.pdf]")]
zips = [a["href"] for a in table.select("td a[href$=.zip]")]
print(pdfs)
print(zips)
Welche gibt Ihnen:
['http://220.227.161.86/28999sm_finalnew_cp-initialpages.pdf', 'http://220.227.161.86/31899sm_finalnew_vol2A_iniipages.pdf', 'http://220.227.161.86/18905sm_finalnew_cp1a.pdf', 'http://220.227.161.86/21520sm_finalnew_vol2_cp1.pdf', 'http://220.227.161.86/18854sm_finalnew_cp2.pdf', 'http://220.227.161.86/21521sm_finalnew_vol2_cp2.pdf', 'http://220.227.161.86/18855sm_finalnew_cp3.pdf', 'http://220.227.161.86/21522sm_finalnew_vol2_cp3.pdf', 'http://220.227.161.86/36605sm_finalnew_feedbackform-m1.pdf', 'http://220.227.161.86/36606sm_finalnew_cp-initialpages-m2.pdf', 'http://220.227.161.86/18856sm_finalnew_cp4.pdf', 'http://220.227.161.86/21523sm_finalnew_vol2_cp4.pdf', 'http://220.227.161.86/18857sm_finalnew_cp5.pdf', 'http://220.227.161.86/21524sm_finalnew_vol2_cp5.pdf', 'http://220.227.161.86/18858sm_finalnew_cp6.pdf', 'http://220.227.161.86/21525sm_finalnew_vol2_cp6.pdf', 'http://220.227.161.86/18859sm_finalnew_cp7.pdf', 'http://220.227.161.86/21526sm_finalnew_vol2_cp7.pdf', 'http://220.227.161.86/18860sm_finalnew_cp8.pdf', 'http://220.227.161.86/21527sm_finalnew_vol2_cp8.pdf', 'http://220.227.161.86/18861sm_finalnew_cp9.pdf', 'http://220.227.161.86/21528sm_finalnew_vol2_cp9.pdf', 'http://220.227.161.86/31901sm_finalnew_cp-feedbackformvolA.pdf', 'http://220.227.161.86/36607sm_finalnew_cp-initialpages-m3.pdf', 'http://220.227.161.86/31900sm_finalnew_vol2B_iniipages.pdf', 'http://220.227.161.86/18862sm_finalnew_cp10.pdf', 'http://220.227.161.86/21529sm_finalnew_vol2_cp10.pdf', 'http://220.227.161.86/18970sm_finalnew_cp11.pdf', 'http://220.227.161.86/21530sm_finalnew_vol2_cp11.pdf', 'http://220.227.161.86/18971sm_finalnew_cp12.pdf', 'http://220.227.161.86/21531sm_finalnew_vol2_cp12.pdf', 'http://220.227.161.86/18863sm_finalnew_cp13.pdf', 'http://220.227.161.86/21532sm_finalnew_vol2_cp13.pdf', 'http://220.227.161.86/18972sm_finalnew_cp14.pdf', 'http://220.227.161.86/21533sm_finalnew_vol2_cp14.pdf', 'http://220.227.161.86/18864sm_finalnew_cp15.pdf', 'http://220.227.161.86/21534sm_finalnew_vol2_cp15.pdf', 'http://220.227.161.86/18865sm_finalnew_cp16.pdf', 'http://220.227.161.86/21535sm_finalnew_vol2_cp16.pdf', 'http://220.227.161.86/29001sm_finalnew_cp-appendix.pdf', 'http://220.227.161.86/31903sm_finalnew_cp-appendix-pmvolab.pdf', 'http://220.227.161.86/29000sm_finalnew_cp-feedbackform.pdf', 'http://220.227.161.86/31902sm_finalnew_cp-feedbackformvolB.pdf']
['http://www.mediafire.com/file/7g7zhhlzmd2u49u/P5Ch1DevelopmentsBusinessEnvironmenP1.zip', 'http://www.mediafire.com/file/tx0dhvlkx9w518s/P5Ch1DevelopmentSBusinessEnvironmentP1.zip', 'http://www.mediafire.com/file/751095mme1hd5z7/P5Ch1DevelopmentsBusinessEnvironmentP2.zip', 'http://www.mediafire.com/file/ifn2nn57czr5djm/P5Ch1DevelopmentsBusinessEnvironmentP2.zip', 'http://www.mediafire.com/file/trf1adc5a1gr4at/P5Ch1DevelopmentsBusinessEnvironmentP3.zip', 'http://www.mediafire.com/file/ofjv0pu00v35ivc/P5Ch1DevelopmentsBusinessEnvironmentP4.zip', 'http://www.mediafire.com/file/us454ahc99llili/P5Ch1DevelopmentsBusinessEnvironmentP4.zip', 'http://www.mediafire.com/file/etps8fn6y26qyyn/P5Ch1DevelopmentsBusinessEnvironmentP5.zip', 'http://www.mediafire.com/file/659coi5bhg8ku50/P5Ch1DevelopmentsBusinessEnvironmentP5.zip', 'http://www.mediafire.com/file/2fhzegia69op9ao/FP5Ch2DecisionMakingAndCVPAnalysisPart1.zip', 'http://www.mediafire.com/file/rrbciytpktmh121/FP5Ch2DecisionMakingAndCVPAnalysisPart1.zip', 'http://www.mediafire.com/file/ivtvwvknl5w7bc7/FP5Ch2DecisionMakingAndCVPAnalysisPart2.zip', 'http://www.mediafire.com/file/ba87eg665dtwaui/FP5Ch2DecisionMakingAndCVPAnalysisPart2.zip', 'http://www.mediafire.com/file/lyzb1yic8l7alst/FP5Ch2DecisionMakingAndCVPAnalysisPart3.zip', 'http://www.mediafire.com/file/8iln8yigbzrla3k/FP5Ch2DecisionMakingAndCVPAnalysisPart3.zip', 'http://www.mediafire.com/file/7aafaoqgsq5dg6u/P5Ch3PricingDecisions.zip', 'http://www.mediafire.com/file/fbmdhlqm8ey3aue/P5Ch3PricingDecisions.zip', 'http://www.mediafire.com/file/0ixhgb0x07qu1an/P5Ch4BudgetP1.zip', 'http://www.mediafire.com/file/wqlk53ol26j4lmm/P5Ch4BudgetP1.zip', 'http://www.mediafire.com/file/b9dsw8sudsud7eg/P5Ch4BudgetP2.zip', 'http://www.mediafire.com/file/mrbw44z2mru2tnw/P5Ch4BudgetP2.zip', 'http://www.mediafire.com/file/hfndpfthdfm7l7s/P5Ch4Budget_3.zip', 'http://www.mediafire.com/file/03yzz48no2ttbta/P5Ch4BudgetP3.zip', 'http://www.mediafire.com/file/usxz01xiuw6rgaj/P5Ch4Budget4.zip', 'http://www.mediafire.com/file/qoyjgu61luvsd71/P5Ch4BudgetP4.zip', 'http://www.mediafire.com/file/m3h6qm2gevdmx4n/P5Ch5StandardCosting.zip', 'http://www.mediafire.com/file/wdj8nsl7to2u6cz/P5Ch5StandardCostingPodcast.zip', 'http://www.mediafire.com/file/x9ypv4oxx573ea4/P5Ch5StandardCostingPart1.zip', 'http://www.mediafire.com/file/ax1taa1ahaga2w3/P5Ch5StandardCostingPart1.zip', 'http://www.mediafire.com/file/z0z0pxp5l44qnz4/P5Ch5StandardCostingPart2.zip', 'http://www.mediafire.com/file/h8stxmsqcdqum9q/P5Ch5StandardCostingPart2.zip', 'http://www.mediafire.com/file/v33bcec4ep6ulxc/P5Ch6CostingofServiceSector.zip', 'http://www.mediafire.com/file/i9y7gebccovv852/P5Ch6CostingofServiceSector.zip', 'http://www.mediafire.com/file/bd61s151fgk1xbs/P5Ch7TransferPricing.zip', 'http://www.mediafire.com/file/iwf47hp8bb6wtdq/P5Ch7TransferPricing.zip', 'http://www.mediafire.com/file/ihn7dz4okrvl8c6/P5Ch8UniformCostingAndIFC.zip', 'http://www.mediafire.com/file/44nqn834616kqvb/P5Ch8UniformCostingAndIFC.zip', 'http://www.mediafire.com/file/hfyr8y6w18klua8/P5Ch9CostsheetPAAndReporting.zip', 'http://www.mediafire.com/file/dnxlsmifismp269/P5Ch9CostSheetPAAndReporting.zip', 'http://www.mediafire.com/file/ef27t3y4ly7zsqa/P5Ch11LINEARPROGRAMMINGPart2.zip', 'http://www.mediafire.com/file/66zwcr87sxu8r08/P5Ch11LINEARPROGRAMMINGV5R.zip', 'http://www.mediafire.com/file/03340dc0g94t3r9/P5Ch11LINEARPROGRAMMINGV5R.zip', 'http://www.mediafire.com/file/i3dcrrbcfcy7xqh/P5Ch11LINEARPROGRAMMINGPart2.zip', 'http://www.mediafire.com/file/j870no55rq8qu55/P5Ch11Transportation_rev.zip', 'http://www.mediafire.com/file/vm75wz1j93s284c/P5Ch11Transportation.zip', 'http://www.mediafire.com/file/0qibqc72f2zdf6g/P5Ch12AssignmentProblem.zip', 'http://www.mediafire.com/file/7iqrbl2ze6wh7mp/P5Ch12AssignmentProblem.zip', 'http://www.mediafire.com/file/nds6vcp6b7ws36h/P5Ch13CriticalpathAnalysis.zip', 'http://www.mediafire.com/file/wurwuaspw9ne954/P5Ch13CriticalpathAnalysis.zip', 'http://www.mediafire.com/file/stxrr65qth1jmi3/P5Ch14PERT.zip', 'http://www.mediafire.com/file/mzlg290e1gy3ce5/P5Ch14PERT.zip', 'http://www.mediafire.com/file/jhad7r6qxexkvug/P5Ch15Simulation.zip', 'http://www.mediafire.com/file/af2r0p99m36uvd4/P5C15SimulationV2.zip', 'http://www.mediafire.com/file/vl59gzd8szy83rw/P5Ch16LearningCurveTheory.zip', 'http://www.mediafire.com/file/439dd5eec4c6u2i/P5Ch16LearningCurveTheory.zip']
Welche genau übereinstimmt, was Sie sehen, auf der Seite.
Wenn Sie nur dann von 1 Spalte wollen und und mit der td Text umzubenennen:
# get second table after cpost
table = soup.select_one("#cpost").select_one("table:nth-of-type(2)")
rows = table.select("tr")
for row in rows:
td1 = row.select_one("td:nth-of-type(1)")
td2 = row.select_one("td:nth-of-type(2)")
l1, l2 = td1.select_one("a[href$=.zip]"), td2.select_one("a[href$=.pdf]")
if l1:
print("Found zip {}".format(l1["href"]))
print(td1.text)
if l2:
print("Found pdf {}".format(l2["href"]))
print(td2.text)
print()
Welche gibt Ihnen:
Found pdf http://220.227.161.86/31899sm_finalnew_vol2A_iniipages.pdf
Initial Pages
Found pdf http://220.227.161.86/21520sm_finalnew_vol2_cp1.pdf
Chapter 1 Developments in the Business Environment
Found zip http://www.mediafire.com/file/751095mme1hd5z7/P5Ch1DevelopmentsBusinessEnvironmentP2.zip
Developments in the Business Environment Part 2
Found zip http://www.mediafire.com/file/ofjv0pu00v35ivc/P5Ch1DevelopmentsBusinessEnvironmentP4.zip
Developments in the Business Environment Part 4
Found zip http://www.mediafire.com/file/etps8fn6y26qyyn/P5Ch1DevelopmentsBusinessEnvironmentP5.zip
Developments in the Business Environment Part 5
Found pdf http://220.227.161.86/21521sm_finalnew_vol2_cp2.pdf
Chapter 2 Decision Making using Cost Concepts and CVP Analysis
Found zip http://www.mediafire.com/file/ivtvwvknl5w7bc7/FP5Ch2DecisionMakingAndCVPAnalysisPart2.zip
Decision Making using Cost Concepts and CVP Analysis part2
Found zip http://www.mediafire.com/file/lyzb1yic8l7alst/FP5Ch2DecisionMakingAndCVPAnalysisPart3.zip
Decision Making using Cost Concepts and CVP Analysis part3
Found pdf http://220.227.161.86/21522sm_finalnew_vol2_cp3.pdf
Chapter 3 Pricing Decisions
Found pdf http://220.227.161.86/21523sm_finalnew_vol2_cp4.pdf
Chapter 4 Budget & Budgetary Control
Found zip http://www.mediafire.com/file/b9dsw8sudsud7eg/P5Ch4BudgetP2.zip
Budget and Budgetary Control Part 2
Found zip http://www.mediafire.com/file/hfndpfthdfm7l7s/P5Ch4Budget_3.zip
Budget and Budgetary Control Part 3
Found zip http://www.mediafire.com/file/usxz01xiuw6rgaj/P5Ch4Budget4.zip
Budget and Budgetary Control Part 4
Found pdf http://220.227.161.86/21524sm_finalnew_vol2_cp5.pdf
Chapter 5 Standard Costing
Found zip http://www.mediafire.com/file/x9ypv4oxx573ea4/P5Ch5StandardCostingPart1.zip
Standard Costing - Part 1
Found zip http://www.mediafire.com/file/z0z0pxp5l44qnz4/P5Ch5StandardCostingPart2.zip
Standard Costing - Part 2
Found pdf http://220.227.161.86/21525sm_finalnew_vol2_cp6.pdf
Chapter 6 Costing of Service Sector
Found pdf http://220.227.161.86/21526sm_finalnew_vol2_cp7.pdf
Chapter 7 Transfer Pricing
Found pdf http://220.227.161.86/21527sm_finalnew_vol2_cp8.pdf
Chapter 8 Uniform Costing & Inter-firm Comparison
Found pdf http://220.227.161.86/21528sm_finalnew_vol2_cp9.pdf
Chapter 9 Cost Sheet, Profitability Analysis and Reporting
Found pdf http://220.227.161.86/31901sm_finalnew_cp-feedbackformvolA.pdf
Feedback Form
Found pdf http://220.227.161.86/31900sm_finalnew_vol2B_iniipages.pdf
Initial Pages
Found pdf http://220.227.161.86/21529sm_finalnew_vol2_cp10.pdf
Chapter 10 Linear Programming
Found zip http://www.mediafire.com/file/03340dc0g94t3r9/P5Ch11LINEARPROGRAMMINGV5R.zip
Linear Programming – Part 2
Found pdf http://220.227.161.86/21530sm_finalnew_vol2_cp11.pdf
Chapter 11 The Transportation Problem
Found pdf http://220.227.161.86/21531sm_finalnew_vol2_cp12.pdf
Chapter 12 The Assignment Problem
Found pdf http://220.227.161.86/21532sm_finalnew_vol2_cp13.pdf
Chapter 13 Critical Path Analysis
Found pdf http://220.227.161.86/21533sm_finalnew_vol2_cp14.pdf
Chapter 14 Program Evaluation and Review Technique
Found pdf http://220.227.161.86/21534sm_finalnew_vol2_cp15.pdf
Chapter 15 Simulation
Found pdf http://220.227.161.86/21535sm_finalnew_vol2_cp16.pdf
Chapter 16 Learning Curve Theory
Found pdf http://220.227.161.86/31903sm_finalnew_cp-appendix-pmvolab.pdf
Appendix
Found pdf http://220.227.161.86/31902sm_finalnew_cp-feedbackformvolB.pdf
Feedback Form
Können Sie den Link teilen? Auch mit Ihrem letzten Code-Snippet bekomme ich jede URL –
Hier ist der Link: http://www.icai.org/post.html?post_id=10160 – Mahesh