Python 例如,html和靓汤

Python 例如,html和靓汤,python,html,hyperlink,beautifulsoup,Python,Html,Hyperlink,Beautifulsoup,我试着做一些类似的事情: from BeautifulSoup import BeautifulSoup import urllib2,unicodedata import re for x in range(1,105): html_page = urllib2.urlopen('http://xxxxxx/BUSCAR/H=1;OR=5;ST=;LIST_ART_PAGENUMBER='+str(x)+';/Dxxxxx.aspx') soup = BeautifulSoup(html_

我试着做一些类似的事情:

from BeautifulSoup import BeautifulSoup
import urllib2,unicodedata
import re

for x in range(1,105):

html_page = urllib2.urlopen('http://xxxxxx/BUSCAR/H=1;OR=5;ST=;LIST_ART_PAGENUMBER='+str(x)+';/Dxxxxx.aspx')
soup = BeautifulSoup(html_page)
for link in soup.findAll('a', attrs={'href': re.compile("^http://xxxxxx/PRODUCTO/PROD_ID")}):
    print link.get('href')
提取链接。我正确地提取链接。但是我想提取1到105的范围

但这不管用

error: expected an indented block

启动for循环时需要缩进。试试这个:

from BeautifulSoup import BeautifulSoup
import urllib2,unicodedata
import re

for x in range(1,105):

    html_page = urllib2.urlopen('http://xxxxxx/BUSCAR/H=1;OR=5;ST=;LIST_ART_PAGENUMBER='+str(x)+';/Dxxxxx.aspx')
    soup = BeautifulSoup(html_page)
    for link in soup.findAll('a', attrs={'href':re.compile("^http://xxxxxx/PRODUCTO/PROD_ID")}):
         print link.get('href')

嗨,DamianPerez,不客气。这是非常基本的,没什么。继续学习!如果你觉得满意,你可以接受这个答案。