如何将Selenium与多个Url一起使用以写入csv

阿卜杜勒
import re
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import csv

oranev = r"^(?!.*Handikaplı).*^(?!.*Yarı).*^(?!.*Alt).*Maç Sonucu.*$[\s\S]*?>1<[\s\S]*?[\>](-|\d\d*\.\d\d|\d\d*)"
oranX = r"^(?!.*Handikaplı).*^(?!.*Yarı).*^(?!.*Alt).*Maç Sonucu.*$[\s\S]*?>X<[\s\S]*?[\>](-|\d\d*\.\d\d|\d\d*)"
orandep = r"^(?!.*Handikaplı).*^(?!.*Yarı).*^(?!.*Alt).*Maç Sonucu.*$[\s\S]*?>2<[\s\S]*?[\>](-|\d\d*\.\d\d|\d\d*)"

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("http://arsiv.mackolik.com/Mac/3495245/Boca-Juniors-Santos")

html_source = driver.page_source
driver.quit()

file = open('oranlar.csv', 'w+', newline='')
writer = csv.writer(file)
writer.writerow(['Ev', 'X', 'Dep'])



oranevoran = re.search(oranev, html_source, re.MULTILINE)
oranxoran = re.search(oranX, html_source, re.MULTILINE)
orandeporan = re.search(orandep, html_source, re.MULTILINE)
print(oranevoran.group(1))
print(oranxoran.group(1))
print(orandeporan.group(1))
writer.writerow([oranevoran.group(1), oranxoran.group(1), orandeporan.group(1)])

当我使用顶部代码时,它在csv中给了我

| Ev | X | Dep |
|----|---|-----|
|1.45 |3.10|4.60  |

我想自动化这个脚本。我想在完成第一个链接然后转到第二个链接时使用。这是我的其他代码。但是我不知道如何产生这个。

import re
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import csv

URLs =["http://arsiv.mackolik.com/Mac/3495245/Boca-Juniors-Santos","http://arsiv.mackolik.com/Mac/3482298/Aris-Saloniki-Volos-NFC"]


oranev = r"^(?!.*Handikaplı).*^(?!.*Yarı).*^(?!.*Alt).*Maç Sonucu.*$[\s\S]*?>1<[\s\S]*?[\>](-|\d\d*\.\d\d|\d\d*)"
oranX = r"^(?!.*Handikaplı).*^(?!.*Yarı).*^(?!.*Alt).*Maç Sonucu.*$[\s\S]*?>X<[\s\S]*?[\>](-|\d\d*\.\d\d|\d\d*)"
orandep = r"^(?!.*Handikaplı).*^(?!.*Yarı).*^(?!.*Alt).*Maç Sonucu.*$[\s\S]*?>2<[\s\S]*?[\>](-|\d\d*\.\d\d|\d\d*)"

for index , url in enumerate(URLs):  #Stack here. i can't figure how to continue

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("url")

html_source = driver.page_source
driver.quit()

file = open('oranlar.csv', 'w+', newline='')
writer = csv.writer(file)
writer.writerow(['Ev', 'X', 'Dep'])



oranevoran = re.search(oranev, html_source, re.MULTILINE)
oranxoran = re.search(oranX, html_source, re.MULTILINE)
orandeporan = re.search(orandep, html_source, re.MULTILINE)
print(oranevoran.group(1))
print(oranxoran.group(1))
print(orandeporan.group(1))
writer.writerow([oranevoran.group(1), oranxoran.group(1), orandeporan.group(1)])

最后我想要我的csv文件

| Ev | X | Dep |
|----|---|-----|
|1.45 |3.10|4.60  |
|next link number|next link number|next link number|

感谢帮助。

尼基塔·加利宾

这样的事情应该起作用:

import re
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import csv

oranev = r"^(?!.*Handikaplı).*^(?!.*Yarı).*^(?!.*Alt).*Maç Sonucu.*$[\s\S]*?>1<[\s\S]*?[\>](-|\d\d*\.\d\d|\d\d*)"
oranX = r"^(?!.*Handikaplı).*^(?!.*Yarı).*^(?!.*Alt).*Maç Sonucu.*$[\s\S]*?>X<[\s\S]*?[\>](-|\d\d*\.\d\d|\d\d*)"
orandep = r"^(?!.*Handikaplı).*^(?!.*Yarı).*^(?!.*Alt).*Maç Sonucu.*$[\s\S]*?>2<[\s\S]*?[\>](-|\d\d*\.\d\d|\d\d*)"

driver = webdriver.Chrome(ChromeDriverManager().install())
URLs =['http://arsiv.mackolik.com/Mac/3495245/Boca-Juniors-Santos",http://arsiv.mackolik.com/Mac/3482298/Aris-Saloniki-Volos-NFC']

file = open('oranlar.csv', 'w+', newline='')
writer = csv.writer(file)
writer.writerow(['Ev', 'X', 'Dep'])

for link in URLs:
  driver.get(link)

  html_source = driver.page_source    
  oranevoran = re.search(oranev, html_source, re.MULTILINE)
  oranxoran = re.search(oranX, html_source, re.MULTILINE)
  orandeporan = re.search(orandep, html_source, re.MULTILINE)
  print(oranevoran.group(1))
  print(oranxoran.group(1))
  print(orandeporan.group(1))
  writer.writerow([oranevoran.group(1), oranxoran.group(1), 
  orandeporan.group(1)])

driver.quit()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何将If语句与布尔值一起使用以及如何读取用户输入

如何将ArgumentOutOfRangeException与多个参数一起使用?

如何将AdControl与多个AdUnitId一起使用?

如何将div与子表一起使用以隐藏数据

如何将TypeScript 1.6与Visual Studio Code一起使用以获得生成器支持?

如何将get_object_or_404与order_by('?')一起使用以获取随机图像

如何将URLSessionStreamTask与URLSession一起使用以进行分块编码传输

如何将Visual Studio 2017与Qt一起使用以开发GUI应用程序?

如何将req()与Shinyjs切换功能一起使用以启用/禁用元素?

如何将AWS凭证与Jenkins一起使用以部署到Elastic Beanstalk?

如何将多个roc一起绘制?

Kotlin:如何将if-else类似条件与let块一起使用以进行“空”检查

如何将QPropertyAnimation与QPainter一起使用以绘制圆弧

Python:如何将asyncio与庞大的csv文件一起使用以从循环发送异步请求?

如何将React Router与Material UI Drawer一起使用以更改点击内容?

如何将case_when与mutate_all一起使用以插入变量值

如何将Safeargs与多个navGraphs一起使用

如何将case_when和grep一起使用以定义新变量

如何将useState与React-redux-firebase一起使用以重新渲染

如何将babel与webpack一起使用以实现ie11兼容性

如何将File.getFreeSpace()与任何文件一起使用以获取Java中的可用空间?

如何将border-radius属性与border-image一起使用以弯曲拐角?

如何将didFinishPickingMedia与多个UIImage一起使用

如何将Autofac与DynamicProxy一起使用以确定目标代理类的名称空间

如何将“ for”循环和“ if”循环一起使用以验证xml文档中xml元素的存在

如何将getFilter()与ListAdapter一起使用以过滤ListView?

如何将ByteBuddy @Pipe批注与@FieldValue一起使用以实现委托模式?

如何将萝卜与 Pycharm 一起使用以实现行为步骤自动完成

如何将 std::bind 与 std::function 一起使用以便将方法作为回调传递?