我正在尝试从使用BeautifulSoup的TD标签和Python 2.7中的请求之间提取文本。到目前为止使用此代码我什么都没得到:(
import requests
from bs4 import BeautifulSoup
# Set up the Spider
def card_search(max_pages):
page = 1
mtgset = 'portal'
card = 'lava-axe'
while page <= max_pages:
url = 'http://www.mtgotraders.com/store/search-results.html?q=lava+axe&x=0&y=0'
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text)
for text in soup.findAll('td',{'class': 'price mod'}):
pagetext = text.get('td')
print(pagetext)
page += 1
card_search(1)
我正在尝试自动排序并重视我的MTG卡集合,因此代码示例中使用的站点的结果非常重要。我知道该网站可以被解析,因为我得到它来返回链接。可悲的是,我无法让纯文本发生。
以下是用于提取链接的代码,但不是针对该表。只是页面本身。
import requests
from bs4 import BeautifulSoup
# Set up the Spider
def card_search(max_pages):
page = 1
mtgset = 'portal'
card = 'lava-axe'
while page <= max_pages:
url = 'http://www.mtgotraders.com/store/search-results.html?q=lava+axe&x=0&y=0'
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text)
for text in soup.findAll('a'):
pagetext = text.get('href')
print(pagetext)
page += 1
card_search(1)
亲切的问候, 酸杰克