【发布时间】:2015-05-29 15:09:30
【问题描述】:
我在 youtube 上关注 thenewboston 的教程,编译我的代码后我没有收到任何错误。
我正在尝试打印“通用行列表”以及该列表后面的所有链接;可以在此链接的底部找到 http://playrustwiki.com/wiki/List_of_Items
import requests
from bs4 import BeautifulSoup
def trade_spider(max_pages):
page = 1
while page <= max_pages: #makes our pages change everytime
url = 'http://playrustwiki.com/wiki/List_of_Items' + str(page)
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text) #find all the links in soup or all the titles
for link in soup.findAll('a', {'class': 'a href'}): #links are a for anchors in HTML
href = link.get('href') # href attribute
print(href)
page += 1
trade_spider(1)
我尝试了不同的 HTML 属性,但我认为这就是我的困惑开始的地方。我找不到正确的属性来调用我的爬虫,或者我调用了错误的属性。
请帮忙~
谢谢:)
【问题讨论】:
标签: python-3.x web-scraping beautifulsoup html-parsing