Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium返回空值_Python_Selenium - Fatal编程技术网

Python Selenium返回空值

Python Selenium返回空值,python,selenium,Python,Selenium,我试图使用Python 3.6上的Selenium从该页面中获取信息: 我需要提取位置框中的文本:“东北极斜坡”。我的代码找到标记,但返回空字符串。我尝试了多种方法来找到它,通过XPath,通过\ id,通过\类,什么都不起作用。谢谢你的帮助 我的代码: options = Options() options.add_argument("--headless") driver = webdriver.Chrome(executable_path='C:/webdrivers/chromedri

我试图使用Python 3.6上的Selenium从该页面中获取信息:

我需要提取位置框中的文本:“东北极斜坡”。我的代码找到标记,但返回空字符串。我尝试了多种方法来找到它,通过XPath,通过\ id,通过\类,什么都不起作用。谢谢你的帮助

我的代码:

options = Options()
options.add_argument("--headless")
driver = webdriver.Chrome(executable_path='C:/webdrivers/chromedriver.exe', options=options)

url = 'http://aogweb.state.ak.us/PoolStatistics/Pool/Overview?poolNo=60100'
driver.get(url)
t.sleep(5)

location = driver.find_elements_by_xpath('//*[@id="location"]')

print(len(location))
print(location[0].text)

它返回长度为1和空文本。为什么它得不到文本

实际上,您正在处理
隐藏的
元素,该元素使用
Java
函数从
后端API
获取,我已经能够在
浏览器
中的
开发工具
下跟踪
XHR
请求,并检查
网络监视器
中的
API

下面你可以轻松实现你的目标

导入请求
导入json
def主(url):
r=requests.get(url).json()
对于r中的项目:
打印(项目['PoolLocation'])
#打印(item.keys()),因为它现在是JSON dict
主要(”http://aogweb.state.ak.us/PoolStatistics/Pool/GetPoolById?poolNo=60100")
输出:

Eastern Arctic Slope
[
    {
        "FieldPool": 60100,
        "WebTitle": "Badami, Badami Oil Pool",
        "Pool_Operator": "Savant Alaska LLC.",
        "Well_Operator": "Conoco Inc.",
        "Well_Nm": "BADAMI 1",
        "Well_Permit": "1891170",
        "Well_API": "50-029-22017-00-00",
        "Wh_Sec": 9,
        "Wh_Twpn": 9,
        "Wh_Twpd": "N",
        "Wh_RngN": 20,
        "Wh_RngD": "E",
        "Wh_Pm": "U",
        "DTD": 13595,
        "TVD": 12911,
        "Dt_Effect": "1990-04-27T00:00:00",
        "PoolStatus": "Producing",
        "PoolLocation": "Eastern Arctic Slope",
        "Text_Summary": "\\\"The Badami Oil Pool was discovered in 1990 and developed through a drilling program lasting from 1997 to 1998.|1|  The 
pool has now been penetrated by 19 well bores, most of which are clustered near the center of the Badami Unit. There are eight additional wells that lie inside of, or within four miles of, the unit boundaries. The Badami Oil Pool is defined in Conservation Order No. 402C, issued September 4, 2012.\r\n\r\nRegular production from the pool began on August 23, 1998,|2|  and peaked at average rate of 7,450 barrels of oil per day (BOPD) during September 1998.|3|  However, production rapidly declined to 3,300 BOPD by January 1999, and the field was shut in from February 4|4|  through April 30, 1999. After facilities were upgraded and remediated, production was restarted on May 1, 1999,|5|  and jumped to an average of nearly 5,300 BOPD during July of 1999. However, by year-end 1999, it declined to an average of less than 3,000 BOPD, and by July 2003 field production averaged less than 1,300 BOPD from six wells.|6|  In August 2003, the Regulatory Commission of Alaska approved BP\u2019s request to temporarily shut down the Badami 
oil pipeline and gas products pipeline for approximately two years.|7|  BP shut-in production and placed the facilities in \u201cwarm shutdown\u201d that same month.|8| \r\n\r\nRegular production from the Badami Pool resumed in September 2005. In October of that year, the pool averaged 1,785 BOPD from five producing wells, but by December average oil production declined to 1,437 BOPD from six producing wells. By July 2007, average oil production declined to 876 BOPD from four producing wells. BP shut the field in to recharge during late August 2007.|9||10| BP joined with Savant Alaska 
LLC, a subsidiary of Savant Resources LLC, in April 2008 to conduct engineering, permitting and inspection operations with the intent of restarting 
Badami.|11|  Late in 2008, Arctic Slope Regional Corporation joined with BP and Savant to revitalize production from the pool by drilling horizontal wells and hydraulically fracturing them.|12|  The pool was returned to regular production in November 2010, and for the first six months of 2011 the pool averaged 1,020 BOPD with no water cut. Since that time, the number 
of producing wells has increased from four to seven and, for the last quarter of 2015, pool production averaged 856 BOPD.  Over the first five months of 2019, the pool averaged 507 BOPD and a water cut of 1.2 percent. For 
the last six months of 2019, the pool averaged 493 BOPD. Savant added a second producer, Badami B1-07, in May 2018, which increased production by about 1,570 BOPD.  Production peaked in January 2019 at 1,754 BOPD, and for 
the first six months of 2019 the pool averaged 1,332 BOPD.|13|  \r\n\r\nAccording to the Alaska Department of Natural Resources\u2019 Case File Number ADL 367011, Tennessee-based Miller Energy Resources Inc. acquired 100% 
interest in Savant Alaska LLC effective December 1, 2014.|14|  Since early 2016, Miller Energy conducts business in Alaska as Glacier Oil & Gas Corp. |15| \\\"",
        "Text_Geology": "The Badami reservoir comprises several separate turbidite sandstone reservoirs assigned to the Tertiary-aged Canning Formation. These sandstone reservoirs were deposited largely as amalgamated channel sands|16|  within mud-dominated submarine fan systems.|17| Published descriptions suggest the reservoirs are complex, comprising 61 identified fans laid down during seven depositional events. Reservoir quality sands are thin  and discontinuous  reservoir quality sands.|18||19| No single well has encountered all of the identified fan systems; the Badami No. 1 exploratory well reportedly penetrated the most complete section.|20| The Badami Oil Pool is defined as the accumulation of hydrocarbons common to and correlating with the interval between the measured depths of 9,500 feet and 
11,500 feet in the Badami No. 1 well.|21|  The reservoir sandstones are very fine-to-fine grained and moderately sorted.|22|  Porosity ranges from 15 to 21 percent, permeability ranges from 1 to 400 md,|23|  and oil gravity reportedly ranges from 19 to 30 degrees API|24||25|.",
        "FolderName": "Badami,Badami_Oil",
        "PoolType": "OIL"
    }
]
用于具有缩进的可读格式

print(json.dumps(r,indent=4))
输出:

Eastern Arctic Slope
[
    {
        "FieldPool": 60100,
        "WebTitle": "Badami, Badami Oil Pool",
        "Pool_Operator": "Savant Alaska LLC.",
        "Well_Operator": "Conoco Inc.",
        "Well_Nm": "BADAMI 1",
        "Well_Permit": "1891170",
        "Well_API": "50-029-22017-00-00",
        "Wh_Sec": 9,
        "Wh_Twpn": 9,
        "Wh_Twpd": "N",
        "Wh_RngN": 20,
        "Wh_RngD": "E",
        "Wh_Pm": "U",
        "DTD": 13595,
        "TVD": 12911,
        "Dt_Effect": "1990-04-27T00:00:00",
        "PoolStatus": "Producing",
        "PoolLocation": "Eastern Arctic Slope",
        "Text_Summary": "\\\"The Badami Oil Pool was discovered in 1990 and developed through a drilling program lasting from 1997 to 1998.|1|  The 
pool has now been penetrated by 19 well bores, most of which are clustered near the center of the Badami Unit. There are eight additional wells that lie inside of, or within four miles of, the unit boundaries. The Badami Oil Pool is defined in Conservation Order No. 402C, issued September 4, 2012.\r\n\r\nRegular production from the pool began on August 23, 1998,|2|  and peaked at average rate of 7,450 barrels of oil per day (BOPD) during September 1998.|3|  However, production rapidly declined to 3,300 BOPD by January 1999, and the field was shut in from February 4|4|  through April 30, 1999. After facilities were upgraded and remediated, production was restarted on May 1, 1999,|5|  and jumped to an average of nearly 5,300 BOPD during July of 1999. However, by year-end 1999, it declined to an average of less than 3,000 BOPD, and by July 2003 field production averaged less than 1,300 BOPD from six wells.|6|  In August 2003, the Regulatory Commission of Alaska approved BP\u2019s request to temporarily shut down the Badami 
oil pipeline and gas products pipeline for approximately two years.|7|  BP shut-in production and placed the facilities in \u201cwarm shutdown\u201d that same month.|8| \r\n\r\nRegular production from the Badami Pool resumed in September 2005. In October of that year, the pool averaged 1,785 BOPD from five producing wells, but by December average oil production declined to 1,437 BOPD from six producing wells. By July 2007, average oil production declined to 876 BOPD from four producing wells. BP shut the field in to recharge during late August 2007.|9||10| BP joined with Savant Alaska 
LLC, a subsidiary of Savant Resources LLC, in April 2008 to conduct engineering, permitting and inspection operations with the intent of restarting 
Badami.|11|  Late in 2008, Arctic Slope Regional Corporation joined with BP and Savant to revitalize production from the pool by drilling horizontal wells and hydraulically fracturing them.|12|  The pool was returned to regular production in November 2010, and for the first six months of 2011 the pool averaged 1,020 BOPD with no water cut. Since that time, the number 
of producing wells has increased from four to seven and, for the last quarter of 2015, pool production averaged 856 BOPD.  Over the first five months of 2019, the pool averaged 507 BOPD and a water cut of 1.2 percent. For 
the last six months of 2019, the pool averaged 493 BOPD. Savant added a second producer, Badami B1-07, in May 2018, which increased production by about 1,570 BOPD.  Production peaked in January 2019 at 1,754 BOPD, and for 
the first six months of 2019 the pool averaged 1,332 BOPD.|13|  \r\n\r\nAccording to the Alaska Department of Natural Resources\u2019 Case File Number ADL 367011, Tennessee-based Miller Energy Resources Inc. acquired 100% 
interest in Savant Alaska LLC effective December 1, 2014.|14|  Since early 2016, Miller Energy conducts business in Alaska as Glacier Oil & Gas Corp. |15| \\\"",
        "Text_Geology": "The Badami reservoir comprises several separate turbidite sandstone reservoirs assigned to the Tertiary-aged Canning Formation. These sandstone reservoirs were deposited largely as amalgamated channel sands|16|  within mud-dominated submarine fan systems.|17| Published descriptions suggest the reservoirs are complex, comprising 61 identified fans laid down during seven depositional events. Reservoir quality sands are thin  and discontinuous  reservoir quality sands.|18||19| No single well has encountered all of the identified fan systems; the Badami No. 1 exploratory well reportedly penetrated the most complete section.|20| The Badami Oil Pool is defined as the accumulation of hydrocarbons common to and correlating with the interval between the measured depths of 9,500 feet and 
11,500 feet in the Badami No. 1 well.|21|  The reservoir sandstones are very fine-to-fine grained and moderately sorted.|22|  Porosity ranges from 15 to 21 percent, permeability ranges from 1 to 400 md,|23|  and oil gravity reportedly ranges from 19 to 30 degrees API|24||25|.",
        "FolderName": "Badami,Badami_Oil",
        "PoolType": "OIL"
    }
]

伪元素!需要执行脚本。您好,谢谢您发布此消息。运行此代码时,我收到以下错误:文件“C:\Users\…\Python36\lib\json\decoder.py”,第357行,在原始解码中,从None json.decoder.jsondeCoderror(“预期值”,s,err.value)中生成JSondeCoderror(“预期值”),预期值:第1行第1列(char 0)和执行打印时(json.dumps(r,indent=4)),我收到以下错误:“Response”类型的对象不可JSON序列化我对JSON不是很精通。是什么导致这些问题?print(r)返回以下信息:@RusLan目前通过电话在线。我一进笔记本电脑就检查一下。@RusLan我刚检查过,它可以正常工作,没有任何问题!您使用的是哪种Python版本?@aԋɱҽԃαМєιcαη我使用3.6。我读了一些关于伪元素的内容,不明白为什么Selenium返回空字符串。我认为Selenium应该能够处理java脚本。我以前从未在硒方面经历过这种情况。为什么json可以处理这个问题而Selenium不能?