如何从.txt文件BeautifulSoup获取URL? 我对网络垃圾还不熟悉。我想做多页废纸,我需要从txt文件中提取这些页面。你知道吗
import pandas as pd
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
chrome_driver_path = r'C:\chromedriver_win32\chromedriver.exe'
driver = webdriver.Chrome(executable_path=chrome_driver_path)
urls = r'C:\chromedriver_win32\asin.txt'
url = ('https://www.amazon.com/dp/'+urls)
driver.get(url)
soup = BeautifulSoup(driver.page_source, 'lxml')
stock = soup.find(id='availability').get_text()
stok_kontrol = pd.DataFrame( { 'Url': [url], 'Stok Durumu': [stock] })
stok_kontrol.to_csv('stok-kontrol.csv', encoding='utf-8-sig')
print(stok_kontrol)
这个记事本有亚马逊asin号码。你知道吗
C:\chromedriver_win32\asin.txt
文件位于:
B00004SU18
B07L9178GQ
B01M35N6CZ
如果我正确理解了这个问题,你只需要把ASIN的数字传给url,告诉BeautifulSoup要刮什么,这只是一个简单的文件操作,然后在文件上循环得到数字,并把每个数字传给BeautifulSoup刮
这将获得产品URL以及产品是否有库存。
将该信息打印到控制台,然后
保存到文件'stok'-康特罗.csv'
测试环境:Python 3.7.4
结果:(文件'stok-康特罗.csv')
相关问题 更多 >
编程相关推荐