|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- url='https://www.alibaba.com/trade/search?fsb=y&IndexArea=product_en&CatId=&SearchText=lift+table'
- headers={
- 'user-agent':'Mozilla/5.0'
- }
- import requests
- import bs4
- res = requests.get(url, headers=headers)
- soup = bs4.BeautifulSoup(res.text, "html.parser")
-
- link = soup.find('div','organic-list-offer-right').find('a')['href']
- print(link)
复制代码
这个页面要提取50个链接,现在我只能提取到一个,怎么能让他循环起来呢
最终代码:
- import requests
- import bs4
- url = 'https://www.alibaba.com/trade/search?fsb=y&IndexArea=product_en&CatId=&SearchText=lift+table'
- headers = {
- 'user-agent': 'Mozilla/5.0'
- }
- for i in range(1, 51):
- res = requests.get(url + f"&page={i}", headers=headers)
- soup = bs4.BeautifulSoup(res.text, "html.parser")
- link = soup.find('div', 'organic-list-offer-right').find('a')['href']
- print(link)
复制代码
|
|