如何在python2.7中使用BeautifulSoup从TD标记和请求之间提取文本

2024-05-14 19:39:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用BeautifulSoup从TD标记和python2.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卡集合进行赋值,因此代码示例中使用的站点的结果非常重要。我知道这个网站可以被解析,因为我让它返回链接。可悲的是,我不能让纯文本发生。在

这里是用于拉链接的代码,但它不是针对表的。只有页面本身。在

^{pr2}$

谨致问候, 酸千斤顶


Tags: 代码text文本importurlsourcesearchpage

热门问题