Мы теперь первая страница сайта www.theft-alerts.com этим кодом:Как царапать на следующих страницах (ссылка)
connection = urllib2.urlopen('http://www.theft-alerts.com')
soup = BeautifulSoup(connection.read().replace("<br>","\n"), "html.parser")
theftalerts = []
for sp in soup.select("table div.itemspacingmodified"):
for wd in sp.select("div.itemindentmodified"):
text = wd.text
if not text.startswith("Images :"):
print(text)
Выход первой страницы:
STOLEN : A LARGE TAYLORS OF LOUGHBOROUGH BELL
Stolen from Bromyard on 7 August 2014
Item : The bell has a diameter of 37 1/2" is approx 3' tall weighs just shy of half a ton and was made by Taylor's of Loughborough in 1902. It is stamped with the numbers 232 and 11.
The bell had come from Co-operative Wholesale Society's Crumpsall Biscuit Works in Manchester.
Any info to : PC 2361. Tel 0300 333 3000
Messages : Send a message
Crime Ref : 22EJ/50213D-14
No of items stolen : 1
Location : UK > Hereford & Worcs
Category : Shop, Pub, Church, Telephone Boxes & Bygones
ID : 84377
User : 1 ; Antique/Reclamation/Salvage Trade ; (Administrator)
Date Created : 11 Aug 2014 15:27:57
Date Modified : 11 Aug 2014 15:37:21;
На веб-сайте, больше страниц (от 1 до 19). Мы видим только страницу 1. Как мы можем получить остальные страницы?
Мы попытались это:
connection = urllib2.urlopen('http://www.theft-alerts.com', 'http://www.theft-alerts.com/index-2.html', 'http://www.theft-alerts.com/index-3.html', 'http://www.theft-alerts.com/index-4.html','http://www.theft-alerts.com/index-5.html', 'http://www.theft-alerts.com/index-6.html', 'http://www.theft-alerts.com/index-7.html')
Но это не работает. Выход:
"You can't pass both context and any of cafile, capath, and "
ValueError: You can't pass both context and any of cafile, capath, and cadefault
Я думаю, вы должны разработать немного больше, объяснить, почему его код не работает и то, что ваш делать – Whitefret
@Whitefret На самом деле, у него нет кода, который сбрасывает ссылки на следующие страницы в настоящий момент – FrozenHeart
Посмотрите на код, он попытался использовать все URL одновременно – Whitefret