小编pb_*_*_ng的帖子

刮擦并将输出写入文本文件

我使用Python 2.7编写了这个刮刀,从TrueLocal.com.au的前3页获取链接,并将它们写入文本文件.

当我运行程序时,只有第一个链接写在文本文件中.我可以做什么,以便返回的所有URL都写在文件上?

import requests
from bs4 import BeautifulSoup

def tru_crawler(max_pages):
    page = 1
    while page <= max_pages:
        url = 'http://www.truelocal.com.au/find/car-rental/' + str(page)
        code = requests.get(url)
        text = code.text
        soup = BeautifulSoup(text)
        for link in soup.findAll('a', {'class':'name'}):
            href = 'http://www.truelocal.com.au' + link.get('href')
            fob = open('c:/test/true.txt', 'w')
            fob.write(href + '\n')
            fob.close()
            print (href)
        page += 1

#Run the function
tru_crawler(3)
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup python-2.7

3
推荐指数
1
解决办法
4348
查看次数

按钮上的悬停效果

我的“添加到购物车”按钮有以下代码

#addToCart {
  background-color: #00AFEF;
  border-radius: 10px;
  width: 300px;
  height: 50px;
  font-size: 18px;
  font-weight: bold;

}
Run Code Online (Sandbox Code Playgroud)

我想在按钮上添加悬停效果,使颜色深 10%。

css button

2
推荐指数
1
解决办法
506
查看次数

标签 统计

beautifulsoup ×1

button ×1

css ×1

python ×1

python-2.7 ×1